Class: Fluidity::Grammer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fluidity/grammer.rb

Direct Known Subclasses

Assert, Be, Must, Should

Instance Method Summary collapse

Constructor Details

#initialize(target, negate = false) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/fluidity/grammer.rb', line 9

def initialize(target, negate=false)
  @target = target
  @negate = negate
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, *a, &b) ⇒ Object

private



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluidity/grammer.rb', line 25

def method_missing(s, *a, &b)
  if assay = (::Assertion.by_name(s) || ::Assertion.by_operator(s))
    if @negate
      assay.refute!(@target, *a, &b)
    else
      assay.assert!(@target, *a, &b)
    end
  else
    q = (s.to_s.end_with?('?') ? s : (s.to_s+'?'))
    if @target.respond_to?(q)
      assert(false, "#{q} failed", caller) unless @target.send(q, *a, &b)
    else
      super(s, *a, &b)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object

Have to override the ususal ‘#==` method to support this.



15
16
17
18
19
20
21
# File 'lib/fluidity/grammer.rb', line 15

def ==(other)
  if @negate
    ::EqualAssay.refute!(@target, other, :backtrace=>caller)
  else
    ::EqualAssay.assert!(@target, other, :backtrace=>caller)
  end
end