Class: DataMapper::Query::Conditions::AbstractComparison
- Inherits:
-
Object
- Object
- DataMapper::Query::Conditions::AbstractComparison
- Extended by:
- Equalizer
- Defined in:
- lib/dm-core/query/conditions/comparison.rb
Overview
A base class for the various comparison classes.
Direct Known Subclasses
EqualToComparison, GreaterThanComparison, GreaterThanOrEqualToComparison, InclusionComparison, LessThanComparison, LessThanOrEqualToComparison, LikeComparison, RegexpComparison
Instance Attribute Summary collapse
- #dumped_value ⇒ Object readonly private
-
#loaded_value ⇒ Object
readonly
The loaded/typecast value.
- #parent ⇒ Object
-
#subject ⇒ Property, Associations::Relationship
readonly
The property or relationship which is being matched against.
Class Method Summary collapse
-
.descendants ⇒ Set<AbstractComparison>
private
Keeps track of AbstractComparison subclasses (used in Comparison).
-
.inherited(descendant) ⇒ Object
private
Registers AbstractComparison subclasses (used in Comparison).
-
.slug(slug = nil) ⇒ Symbol
Setter/getter: allows subclasses to easily set their slug.
Instance Method Summary collapse
-
#inspect ⇒ String
Returns a human-readable representation of this object.
-
#matches?(record) ⇒ Boolean
Test that the record value matches the comparison.
- #negated? ⇒ Boolean private
-
#property? ⇒ Boolean
Returns whether the subject is a Property.
-
#relationship? ⇒ Boolean
Returns whether the subject is a Relationship.
-
#slug ⇒ Symbol
private
Return the comparison class slug.
-
#to_s ⇒ String
Returns a string version of this Comparison object.
-
#valid? ⇒ Boolean
Tests that the Comparison is valid.
-
#value ⇒ Object
Value to be compared with the subject.
Methods included from Equalizer
Instance Attribute Details
#dumped_value ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
271 272 273 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 271 def dumped_value @dumped_value end |
#loaded_value ⇒ Object (readonly)
The loaded/typecast value
In the case of primitive types, this will be the same as value, however when using primitive property this stores the loaded value.
If writing an adapter, you should use value, while plugin authors should refer to loaded_value.
– As an example, you might use symbols with the Enum type in dm-types
property :myprop, Enum[:open, :closed]
These are stored in repositories as 1 and 2, respectively. value returns the 1 or 2, while loaded_value returns the symbol. ++
147 148 149 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 147 def loaded_value @loaded_value end |
#parent ⇒ Object
102 103 104 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 102 def parent @parent end |
#subject ⇒ Property, Associations::Relationship (readonly)
The property or relationship which is being matched against
109 110 111 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 109 def subject @subject end |
Class Method Details
.descendants ⇒ Set<AbstractComparison>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Keeps track of AbstractComparison subclasses (used in Comparison)
153 154 155 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 153 def self.descendants @descendants ||= DescendantSet.new end |
.inherited(descendant) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Registers AbstractComparison subclasses (used in Comparison)
160 161 162 163 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 160 def self.inherited(descendant) descendants << descendant super end |
.slug(slug = nil) ⇒ Symbol
Setter/getter: allows subclasses to easily set their slug
180 181 182 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 180 def self.slug(slug = nil) slug ? @slug = slug : @slug end |
Instance Method Details
#inspect ⇒ String
Returns a human-readable representation of this object
246 247 248 249 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 246 def inspect "#<#{self.class} @subject=#{@subject.inspect} " \ "@dumped_value=#{@dumped_value.inspect} @loaded_value=#{@loaded_value.inspect}>" end |
#matches?(record) ⇒ Boolean
Test that the record value matches the comparison
202 203 204 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 202 def matches?(record) match_property?(record) end |
#negated? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
265 266 267 268 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 265 def negated? parent = self.parent parent ? parent.negated? : false end |
#property? ⇒ Boolean
Returns whether the subject is a Property
237 238 239 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 237 def property? subject.is_a?(Property) end |
#relationship? ⇒ Boolean
Returns whether the subject is a Relationship
228 229 230 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 228 def relationship? false end |
#slug ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the comparison class slug
190 191 192 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 190 def slug self.class.slug end |
#to_s ⇒ String
Returns a string version of this Comparison object
260 261 262 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 260 def to_s "#{subject.name} #{comparator_string} #{dumped_value.inspect}" end |
#valid? ⇒ Boolean
Tests that the Comparison is valid
Subclasses can overload this to customise the means by which they determine the validity of the comparison. #valid? is called prior to performing a query on the repository: each Comparison within a Query must be valid otherwise the query will not be performed.
219 220 221 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 219 def valid? valid_for_subject?(loaded_value) end |
#value ⇒ Object
Value to be compared with the subject
This value is compared against that contained in the subject when filtering collections, or the value in the repository when performing queries.
In the case of primitive property, this is the value as it is stored in the repository.
123 124 125 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 123 def value dumped_value end |