Module: MongoModel::Scope::QueryMethods

Included in:
MongoModel::Scope
Defined in:
lib/mongomodel/support/scope/query_methods.rb

Instance Method Summary collapse

Instance Method Details

#from(value, &block) ⇒ Object


41
42
43
44
45
# File 'lib/mongomodel/support/scope/query_methods.rb', line 41

def from(value, &block)
  new_scope = clone
  new_scope.from_value = InstrumentedCollection.new(value.is_a?(String) ? klass.database.collection(value) : value)
  new_scope
end

#initializeObject


4
5
6
7
# File 'lib/mongomodel/support/scope/query_methods.rb', line 4

def initialize(*)
  SINGLE_VALUE_METHODS.each { |m| instance_variable_set("@#{m}_value", nil) }
  MULTI_VALUE_METHODS.each { |m| instance_variable_set("@#{m}_values", []) }
end

#reverse_orderObject


47
48
49
50
51
52
53
# File 'lib/mongomodel/support/scope/query_methods.rb', line 47

def reverse_order
  if order_values.empty?
    order(:id.desc)
  else
    except(:order).order(MongoOrder.parse(order_values).reverse.to_a)
  end
end