class MongoModel::MongoOrder::Clause
Attributes
field[R]
order[R]
Public Class Methods
new(field, order=:ascending)
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 54 def initialize(field, order=:ascending) @field, @order = field.to_sym, order.to_sym end
parse(clause)
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 79 def self.parse(clause) case clause when Clause clause when String, Symbol field, order = clause.to_s.strip.split(/ /) new(field, order =~ /^desc/i ? :descending : :ascending) else clause.to_mongo_order_clause if clause.respond_to?(:to_mongo_order_clause) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 70 def ==(other) other.is_a?(self.class) && field == other.field && order == other.order end
Also aliased as: eql?
hash()
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 75 def hash [field, order].hash end
reverse()
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 66 def reverse self.class.new(field, order == :ascending ? :descending : :ascending) end
to_s()
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 58 def to_s "#{field} #{order}" end
to_sort(property)
click to toggle source
# File lib/mongomodel/support/mongo_order.rb, line 62 def to_sort(property) [property ? property.as : field.to_s, order] end