class Be::Delegator

Delegator acts as the go-between between the subjunctive call and the Assertor.

Public Class Methods

new(criteria={}) click to toggle source

Initialize new Delegator.

# File lib/be/delegator.rb, line 11
def initialize(criteria={})
  @criteria = criteria
  @messages = []
end

Public Instance Methods

==(other) click to toggle source
# File lib/be/delegator.rb, line 37
def ==(other)
  @messages << [:==, [other], nil]
  self
end
equal?(other) click to toggle source
# File lib/be/delegator.rb, line 42
def equal?(other)
  @messages << [:==, [other], nil]
  self
end
method_missing(name, *args, &blk) click to toggle source
# File lib/be/delegator.rb, line 32
def method_missing(name, *args, &blk)
  @messages << [name, args, blk]
  self
end
to_assertor() click to toggle source

Convert to Assertor. If ‘@messages` is empty then defaults to calling method given by `criteria` or `#==` failing that.

# File lib/be/delegator.rb, line 21
def to_assertor
  if @messages.empty?
    default  = @criteria.delete(:default) || :==
    measure  = @criteria.delete(:measure)
    messages = [[default, [measure], nil]]
    Assertor.new(messages, @criteria)
  else
    Assertor.new(@messages, @criteria)
  end
end