Class: DataMapper::Query::Conditions::AbstractComparison
- Inherits:
-
Object
- Object
- DataMapper::Query::Conditions::AbstractComparison
- 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
-
#loaded_value ⇒ Object
readonly
The loaded/typecast value.
-
#subject ⇒ Property, Associations::Relationship
readonly
The property or relationship which is being matched against.
-
#value ⇒ Object
readonly
Value to be compared with the subject.
Class Method Summary collapse
-
.descendants ⇒ Set<AbstractComparison>
private
Keeps track of AbstractComparison subclasses (used in Comparison).
-
.inherited(comparison_class) ⇒ 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.
-
#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.
Methods included from Deprecate
Methods included from Equalizer
Instance Attribute Details
#loaded_value ⇒ Object (readonly)
The loaded/typecast value
In the case of primitive types, this will be the same as value
, however when using custom types 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. ++
158 159 160 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 158 def loaded_value @loaded_value end |
#subject ⇒ Property, Associations::Relationship (readonly)
The property or relationship which is being matched against
122 123 124 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 122 def subject @subject end |
#value ⇒ Object (readonly)
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 custom types, this is the value as it is stored in the repository.
136 137 138 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 136 def value @value 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)
164 165 166 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 164 def self.descendants @descendants ||= Set.new end |
.inherited(comparison_class) ⇒ 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)
171 172 173 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 171 def self.inherited(comparison_class) descendants << comparison_class end |
.slug(slug = nil) ⇒ Symbol
Setter/getter: allows subclasses to easily set their slug
190 191 192 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 190 def self.slug(slug = nil) slug ? @slug = slug : @slug end |
Instance Method Details
#inspect ⇒ String
Returns a human-readable representation of this object
248 249 250 251 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 248 def inspect "#<#{self.class} @subject=#{@subject.inspect} " \ "@value=#{@value.inspect} @loaded_value=#{@loaded_value.inspect}>" end |
#property? ⇒ Boolean
Returns whether the subject is a Property
239 240 241 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 239 def property? subject.kind_of?(Property) end |
#relationship? ⇒ Boolean
Returns whether the subject is a Relationship
230 231 232 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 230 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
200 201 202 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 200 def slug self.class.slug end |
#to_s ⇒ String
Returns a string version of this Comparison object
262 263 264 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 262 def to_s "#{@subject} #{comparator_string} #{@value}" 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.
217 218 219 220 221 222 223 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 217 def valid? # This needs to be deferred until the last moment because the value # could be a reference to a Resource, that when the comparison was # created was invalid, but has since been saved and has it's key # set. subject.valid?(loaded_value) end |