Class: DataMapper::Query::Conditions::InclusionComparison
- Inherits:
-
AbstractComparison
- Object
- AbstractComparison
- DataMapper::Query::Conditions::InclusionComparison
- Includes:
- RelationshipHandler
- Defined in:
- lib/dm-core/query/conditions/comparison.rb
Overview
Tests whether the value in the record is contained in the expected_value set for the Comparison, where expected_value is an Array, Range, or Set.
Instance Attribute Summary
Attributes inherited from AbstractComparison
#loaded_value, #subject, #value
Instance Method Summary collapse
-
#matches?(record) ⇒ Boolean
Asserts that the record value matches the comparison.
-
#valid? ⇒ Boolean
Checks that the Comparison is valid.
Methods included from RelationshipHandler
#foreign_key_mapping, #relationship?
Methods inherited from AbstractComparison
descendants, inherited, #inspect, #property?, #relationship?, #slug, slug, #to_s
Methods included from Deprecate
Methods included from Equalizer
Instance Method Details
#matches?(record) ⇒ Boolean
Asserts that the record value matches the comparison
511 512 513 514 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 511 def matches?(record) record_value = record_value(record) !record_value.nil? && expected.include?(record_value) end |
#valid? ⇒ Boolean
Checks that the Comparison is valid
523 524 525 526 527 528 529 530 531 532 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 523 def valid? case value when Array, Set loaded_value.any? && loaded_value.all? { |val| subject.valid?(val) } when Range loaded_value.any? && subject.valid?(loaded_value.first) && subject.valid?(loaded_value.last) else false end end |