Class: Mongoid::Criteria::Queryable::Key
- Inherits:
-
Object
- Object
- Mongoid::Criteria::Queryable::Key
- Defined in:
- lib/mongoid/criteria/queryable/key.rb
Overview
The key is a representation of a field in a queryable, that can be expanded to special MongoDB selectors.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
- #block The optional block to transform values.(Theoptionalblocktotransformvalues.) ⇒ Object readonly
-
#expanded ⇒ Object
readonly
Returns the value of attribute expanded.
- #expanded The MongoDB expanded query operator.(TheMongoDBexpandedqueryoperator.) ⇒ Object readonly
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #name The name of the field.(Thenameofthefield.) ⇒ Object readonly
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
- #operator The MongoDB query operator.(TheMongoDBqueryoperator.) ⇒ Object readonly
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
- #strategy The name of the merge strategy.(Thenameofthemergestrategy.) ⇒ Object readonly
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Does the key equal another object?.
-
#__expr_part__(object, negating = false) ⇒ Hash
Gets the raw selector that would be passed to Mongo from this key.
-
#__sort_option__ ⇒ Hash
(also: #__sort_pair__)
Get the key as raw Mongo sorting options.
-
#hash ⇒ Fixnum
Calculate the hash code for a key.
-
#initialize(name, strategy, operator, expanded = nil, &block) ⇒ Key
constructor
Instantiate the new key.
-
#to_s ⇒ String
Convert the key to a string.
Constructor Details
#initialize(name, strategy, operator, expanded = nil, &block) ⇒ Key
Instantiate the new key.
54 55 56 57 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 54 def initialize(name, strategy, operator, = nil, &block) @name, @strategy, @operator, @expanded, @block = name, strategy, operator, , block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 def block @block end |
#block The optional block to transform values.(Theoptionalblocktotransformvalues.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 attr_reader :block, :name, :operator, :expanded, :strategy |
#expanded ⇒ Object (readonly)
Returns the value of attribute expanded.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 def @expanded end |
#expanded The MongoDB expanded query operator.(TheMongoDBexpandedqueryoperator.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 attr_reader :block, :name, :operator, :expanded, :strategy |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 def name @name end |
#name The name of the field.(Thenameofthefield.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 attr_reader :block, :name, :operator, :expanded, :strategy |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 def operator @operator end |
#operator The MongoDB query operator.(TheMongoDBqueryoperator.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 attr_reader :block, :name, :operator, :expanded, :strategy |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
15 16 17 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 def strategy @strategy end |
#strategy The name of the merge strategy.(Thenameofthemergestrategy.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 15 attr_reader :block, :name, :operator, :expanded, :strategy |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Does the key equal another object?
28 29 30 31 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 28 def ==(other) return false unless other.is_a?(Key) name == other.name && operator == other.operator && == other. end |
#__expr_part__(object, negating = false) ⇒ Hash
Gets the raw selector that would be passed to Mongo from this key.
70 71 72 73 74 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 70 def __expr_part__(object, negating = false) value = block ? block[object] : object expression = { operator => ? { => value } : value } { name.to_s => (negating && operator != "$not") ? { "$not" => expression } : expression } end |
#__sort_option__ ⇒ Hash Also known as: __sort_pair__
Get the key as raw Mongo sorting options.
84 85 86 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 84 def __sort_option__ { name => operator } end |
#hash ⇒ Fixnum
Calculate the hash code for a key.
39 40 41 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 39 def hash [name, operator, ].hash end |
#to_s ⇒ String
Convert the key to a string.
97 98 99 |
# File 'lib/mongoid/criteria/queryable/key.rb', line 97 def to_s @name.to_s end |