Class: Inspector::Constraints::Predicate

Inherits:
Object
  • Object
show all
Includes:
Inspector::Constraint
Defined in:
lib/inspector/constraints/predicate.rb

Instance Method Summary collapse

Methods included from Inspector::Constraint

#negate!, #positive?, #validator

Constructor Details

#initialize(method, *args, &block) ⇒ Predicate

Returns a new instance of Predicate.



6
7
8
9
10
# File 'lib/inspector/constraints/predicate.rb', line 6

def initialize(method, *args, &block)
  @method = method
  @args = args
  @block = block
end

Instance Method Details

#inspectObject



33
34
35
# File 'lib/inspector/constraints/predicate.rb', line 33

def inspect
  "#<#{@method}>"
end

#to_sObject



29
30
31
# File 'lib/inspector/constraints/predicate.rb', line 29

def to_s
  "be_#{@method}"
end

#valid?(actual) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/inspector/constraints/predicate.rb', line 12

def valid?(actual)
  result = false

  begin
    result = actual.__send__("#{@method}?", *@args, &@block)
  rescue NameError
  end

  begin
    result  = actual.__send__("#{@method}s?", *@args, &@block)
    @method = "#{@method}s"
  rescue NameError
  end

  return result
end