Parent

Origin::Key

The key is a representation of a field in a queryable, that can be expanded to special MongoDB selectors.

Attributes

block[R]

@attribute [r] name The name of the field. @attribute [r] block The optional block to transform values. @attribute [r] operator The MongoDB query operator. @attribute [r] expanded The MongoDB expanded query operator. @attribute [r] strategy The name of the merge strategy.

expanded[R]

@attribute [r] name The name of the field. @attribute [r] block The optional block to transform values. @attribute [r] operator The MongoDB query operator. @attribute [r] expanded The MongoDB expanded query operator. @attribute [r] strategy The name of the merge strategy.

name[R]

@attribute [r] name The name of the field. @attribute [r] block The optional block to transform values. @attribute [r] operator The MongoDB query operator. @attribute [r] expanded The MongoDB expanded query operator. @attribute [r] strategy The name of the merge strategy.

operator[R]

@attribute [r] name The name of the field. @attribute [r] block The optional block to transform values. @attribute [r] operator The MongoDB query operator. @attribute [r] expanded The MongoDB expanded query operator. @attribute [r] strategy The name of the merge strategy.

strategy[R]

@attribute [r] name The name of the field. @attribute [r] block The optional block to transform values. @attribute [r] operator The MongoDB query operator. @attribute [r] expanded The MongoDB expanded query operator. @attribute [r] strategy The name of the merge strategy.

Public Class Methods

new(name, strategy, operator, expanded = nil, &block) click to toggle source

Instantiate the new key.

@example Instantiate the key.

Key.new("age", "$gt")

@param [ String, Symbol ] name The field name. @param [ Symbol ] strategy The name of the merge strategy. @param [ String ] operator The Mongo operator. @param [ String ] expanded The Mongo expanded operator.

@since 1.0.0

# File lib/origin/key.rb, line 40
def initialize(name, strategy, operator, expanded = nil, &block)
  @name, @strategy, @operator, @expanded, @block =
    name, strategy, operator, expanded, block
end

Public Instance Methods

==(other) click to toggle source

Does the key equal another object?

@example Is the key equal to another?

key == other

@param [ Object ] other The object to compare to.

@return [ true, false ] If the objects are equal.

@since 1.0.0

# File lib/origin/key.rb, line 24
def ==(other)
  return false unless other.is_a?(Key)
  name == other.name && operator == other.operator && expanded == other.expanded
end
__sort_option__() click to toggle source

Get the key as raw Mongo sorting options.

@example Get the key as a sort.

key.__sort_option__

@return [ Hash ] The field/direction pair.

@since 1.0.0

# File lib/origin/key.rb, line 70
def __sort_option__
  { name => operator }
end
Also aliased as: __sort_pair__
__sort_pair__() click to toggle source
Alias for: __sort_option__
specify(object, negating = false) click to toggle source

Gets the raw selector that would be passed to Mongo from this key.

@example Specify the raw selector.

key.specify(50)

@param [ Object ] object The value to be included. @param [ true, false ] negating If the selection should be negated.

@return [ Hash ] The raw MongoDB selector.

@since 1.0.0

# File lib/origin/key.rb, line 56
def specify(object, negating = false)
  value = block ? block[object] : object
  expression = { operator => expanded ? { expanded => value } : value }
  { name.to_s => negating ? { "$not" => expression } : expression }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.