Module: Inspector::Constraints::Have

Includes:
Inspector::Constraint
Included in:
AtLeast, AtMost, Exactly
Defined in:
lib/inspector/constraints/have.rb

Defined Under Namespace

Classes: AtLeast, AtMost, Exactly

Instance Method Summary collapse

Methods included from Inspector::Constraint

#negate!, #positive?, #validator

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



61
62
63
64
65
66
# File 'lib/inspector/constraints/have.rb', line 61

def method_missing(method, *args, &block)
  @collection_name = method
  @args = args
  @block = block
  self
end

Instance Method Details

#initialize(expected) ⇒ Object



42
43
44
# File 'lib/inspector/constraints/have.rb', line 42

def initialize(expected)
  @expected        = expected.to_i
end

#inspectObject



53
54
55
56
57
58
59
# File 'lib/inspector/constraints/have.rb', line 53

def inspect
  "#<%{constraint} %{expected}%{collection}>" % {
    :constraint => to_s.split('_').join(' '),
    :expected   => @expected.inspect,
    :collection => " #{@collection_name}".rstrip
  }
end

#valid?(collection_or_owner) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/inspector/constraints/have.rb', line 46

def valid?(collection_or_owner)
  collection = determine_collection(collection_or_owner)
  return false if collection.nil?
  query_method = determine_query_method(collection)
  compare(collection.__send__(query_method))
end