Class: MongoModel::MongoOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/support/mongo_order.rb

Defined Under Namespace

Classes: Clause

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*clauses) ⇒ MongoOrder



5
6
7
# File 'lib/mongomodel/support/mongo_order.rb', line 5

def initialize(*clauses)
  @clauses = clauses
end

Instance Attribute Details

#clausesObject (readonly)

Returns the value of attribute clauses



3
4
5
# File 'lib/mongomodel/support/mongo_order.rb', line 3

def clauses
  @clauses
end

Class Method Details

.parse(order) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mongomodel/support/mongo_order.rb', line 34

def self.parse(order)
  case order
  when MongoOrder
    order
  when Clause
    new(order)
  when Symbol
    new(Clause.new(order))
  when String
    new(*order.split(',').map { |c| Clause.parse(c) })
  when Array
    new(*order.map { |c| Clause.parse(c) })
  else
    new(order.to_mongo_order_clause) if order.respond_to?(:to_mongo_order_clause)
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



21
22
23
# File 'lib/mongomodel/support/mongo_order.rb', line 21

def ==(other)
  other.is_a?(self.class) && clauses == other.clauses
end

#hashObject



26
27
28
# File 'lib/mongomodel/support/mongo_order.rb', line 26

def hash
  clauses.hash
end

#reverseObject



30
31
32
# File 'lib/mongomodel/support/mongo_order.rb', line 30

def reverse
  self.class.new(*clauses.map { |c| c.reverse })
end

#to_aObject



9
10
11
# File 'lib/mongomodel/support/mongo_order.rb', line 9

def to_a
  clauses
end

#to_sObject



13
14
15
# File 'lib/mongomodel/support/mongo_order.rb', line 13

def to_s
  clauses.map { |c| c.to_s }.join(', ')
end

#to_sort(model) ⇒ Object



17
18
19
# File 'lib/mongomodel/support/mongo_order.rb', line 17

def to_sort(model)
  clauses.map { |c| c.to_sort(model.respond_to?(:properties) ? model.properties[c.field] : nil) }
end