Class: ActiveHash::Relation::Condition
- Inherits:
-
Object
- Object
- ActiveHash::Relation::Condition
- Defined in:
- lib/active_hash/condition.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#inverted ⇒ Object
readonly
Returns the value of attribute inverted.
Instance Method Summary collapse
-
#initialize(constraints) ⇒ Condition
constructor
A new instance of Condition.
- #invert! ⇒ Object
- #matches?(record) ⇒ Boolean
Constructor Details
#initialize(constraints) ⇒ Condition
Returns a new instance of Condition.
4 5 6 7 |
# File 'lib/active_hash/condition.rb', line 4 def initialize(constraints) @constraints = constraints @inverted = false end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
2 3 4 |
# File 'lib/active_hash/condition.rb', line 2 def constraints @constraints end |
#inverted ⇒ Object (readonly)
Returns the value of attribute inverted.
2 3 4 |
# File 'lib/active_hash/condition.rb', line 2 def inverted @inverted end |
Instance Method Details
#invert! ⇒ Object
9 10 11 12 13 |
# File 'lib/active_hash/condition.rb', line 9 def invert! @inverted = !inverted self end |
#matches?(record) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_hash/condition.rb', line 15 def matches?(record) match = begin return true unless constraints expectation_method = inverted ? :any? : :all? constraints.send(expectation_method) do |attribute, expected| value = record.read_attribute(attribute) matches_value?(value, expected) end end inverted ? !match : match end |