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)
-
- (Object) block
readonly
Returns the value of attribute block.
- - (Object) block The optional block to transform values. readonly
-
- (Object) expanded
readonly
Returns the value of attribute expanded.
- - (Object) expanded The MongoDB expanded query operator. readonly
-
- (Object) name
readonly
Returns the value of attribute name.
- - (Object) name The name of the field. readonly
-
- (Object) operator
readonly
Returns the value of attribute operator.
- - (Object) operator The MongoDB query operator. readonly
-
- (Object) strategy
readonly
Returns the value of attribute strategy.
- - (Object) strategy The name of the merge strategy. readonly
Instance Method Summary (collapse)
-
- (true, false) ==(other)
Does the key equal another object?.
-
- (Hash) __sort_option__
(also: #__sort_pair__)
Get the key as raw Mongo sorting options.
-
- (Key) initialize(name, strategy, operator, expanded = nil, &block)
constructor
Instantiate the new key.
-
- (Hash) specify(object, negating = false)
Gets the raw selector that would be passed to Mongo from this key.
Constructor Details
- (Key) initialize(name, strategy, operator, expanded = nil, &block)
Instantiate the new key.
41 42 43 44 |
# File 'lib/origin/key.rb', line 41 def initialize(name, strategy, operator, = nil, &block) @name, @strategy, @operator, @expanded, @block = name, strategy, operator, , block end |
Instance Attribute Details
- (Object) block (readonly)
Returns the value of attribute block
13 14 15 |
# File 'lib/origin/key.rb', line 13 def block @block end |
- (Object) block The optional block to transform values. (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
- (Object) expanded (readonly)
Returns the value of attribute expanded
13 14 15 |
# File 'lib/origin/key.rb', line 13 def @expanded end |
- (Object) expanded The MongoDB expanded query operator. (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
- (Object) name (readonly)
Returns the value of attribute name
13 14 15 |
# File 'lib/origin/key.rb', line 13 def name @name end |
- (Object) name The name of the field. (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
- (Object) operator (readonly)
Returns the value of attribute operator
13 14 15 |
# File 'lib/origin/key.rb', line 13 def operator @operator end |
- (Object) operator The MongoDB query operator. (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
- (Object) strategy (readonly)
Returns the value of attribute strategy
13 14 15 |
# File 'lib/origin/key.rb', line 13 def strategy @strategy end |
- (Object) strategy The name of the merge strategy. (readonly)
13 |
# File 'lib/origin/key.rb', line 13 attr_reader :block, :name, :operator, :expanded, :strategy |
Instance Method Details
- (true, false) ==(other)
Does the key equal another object?
25 26 27 28 |
# File 'lib/origin/key.rb', line 25 def ==(other) return false unless other.is_a?(Key) name == other.name && operator == other.operator && == other. end |
- (Hash) __sort_option__ Also known as: __sort_pair__
Get the key as raw Mongo sorting options.
71 72 73 |
# File 'lib/origin/key.rb', line 71 def __sort_option__ { name => operator } end |
- (Hash) specify(object, negating = false)
Gets the raw selector that would be passed to Mongo from this key.
57 58 59 60 61 |
# File 'lib/origin/key.rb', line 57 def specify(object, negating = false) value = block ? block[object] : object expression = { operator => ? { => value } : value } { name.to_s => negating ? { "$not" => expression } : expression } end |