Class: Origin::Key
- Inherits:
-
Object
- Object
- Origin::Key
- Defined in:
- lib/origin/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.
52 53 54 55 |
# File 'lib/origin/key.rb', line 52 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.
13 14 15 |
# File 'lib/origin/key.rb', line 13 def block @block end |
#block The optional block to transform values.(Theoptionalblocktotransformvalues.) ⇒ Object (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
#expanded ⇒ Object (readonly)
Returns the value of attribute expanded.
13 14 15 |
# File 'lib/origin/key.rb', line 13 def @expanded end |
#expanded The MongoDB expanded query operator.(TheMongoDBexpandedqueryoperator.) ⇒ Object (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/origin/key.rb', line 13 def name @name end |
#name The name of the field.(Thenameofthefield.) ⇒ Object (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
13 14 15 |
# File 'lib/origin/key.rb', line 13 def operator @operator end |
#operator The MongoDB query operator.(TheMongoDBqueryoperator.) ⇒ Object (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
13 14 15 |
# File 'lib/origin/key.rb', line 13 def strategy @strategy end |
#strategy The name of the merge strategy.(Thenameofthemergestrategy.) ⇒ Object (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Does the key equal another object?
26 27 28 29 |
# File 'lib/origin/key.rb', line 26 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.
68 69 70 71 72 |
# File 'lib/origin/key.rb', line 68 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.
82 83 84 |
# File 'lib/origin/key.rb', line 82 def __sort_option__ { name => operator } end |
#hash ⇒ Fixnum
Calculate the hash code for a key.
37 38 39 |
# File 'lib/origin/key.rb', line 37 def hash [name, operator, ].hash end |
#to_s ⇒ String
Convert the key to a string.
95 96 97 |
# File 'lib/origin/key.rb', line 95 def to_s @name.to_s end |