Class: MongoModel::MongoOrder::Clause
- Inherits:
-
Object
- Object
- MongoModel::MongoOrder::Clause
- Defined in:
- lib/mongomodel/support/mongo_order.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(field, order = :ascending) ⇒ Clause
constructor
A new instance of Clause.
- #reverse ⇒ Object
- #to_s ⇒ Object
- #to_sort(property) ⇒ Object
Constructor Details
#initialize(field, order = :ascending) ⇒ Clause
Returns a new instance of Clause.
54 55 56 |
# File 'lib/mongomodel/support/mongo_order.rb', line 54 def initialize(field, order=:ascending) @field, @order = field.to_sym, order.to_sym end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
52 53 54 |
# File 'lib/mongomodel/support/mongo_order.rb', line 52 def field @field end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
52 53 54 |
# File 'lib/mongomodel/support/mongo_order.rb', line 52 def order @order end |
Class Method Details
.parse(clause) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# 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 |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
70 71 72 |
# File 'lib/mongomodel/support/mongo_order.rb', line 70 def ==(other) other.is_a?(self.class) && field == other.field && order == other.order end |
#hash ⇒ Object
75 76 77 |
# File 'lib/mongomodel/support/mongo_order.rb', line 75 def hash [field, order].hash end |
#reverse ⇒ Object
66 67 68 |
# File 'lib/mongomodel/support/mongo_order.rb', line 66 def reverse self.class.new(field, order == :ascending ? :descending : :ascending) end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/mongomodel/support/mongo_order.rb', line 58 def to_s "#{field} #{order}" end |
#to_sort(property) ⇒ Object
62 63 64 |
# File 'lib/mongomodel/support/mongo_order.rb', line 62 def to_sort(property) [property ? property.as : field.to_s, order] end |