Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/ximate/activerecord/relation.rb
Instance Attribute Summary collapse
-
#ranks ⇒ Object
Returns the value of attribute ranks.
Instance Method Summary collapse
-
#initialize(klass, table) ⇒ Relation
constructor
A new instance of Relation.
- #order(*args) ⇒ Object
- #orig_initialize ⇒ Object
- #orig_order ⇒ Object
Constructor Details
#initialize(klass, table) ⇒ Relation
Returns a new instance of Relation.
9 10 11 12 |
# File 'lib/ximate/activerecord/relation.rb', line 9 def initialize(klass, table) @ranks = {} orig_initialize(klass, table) end |
Instance Attribute Details
#ranks ⇒ Object
Returns the value of attribute ranks.
4 5 6 |
# File 'lib/ximate/activerecord/relation.rb', line 4 def ranks @ranks end |
Instance Method Details
#order(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ximate/activerecord/relation.rb', line 14 def order(*args) if args[0] =~ /^rank/i unless @ranks.empty? tokens = args[0].split(' ') verse = tokens[1] if tokens[1] =~ /^(asc|desc)$/i verse ||= 'ASC' id_ordered = @ranks.keys.sort{|x,y| @ranks[x] <=> @ranks[y]} orig_order("FIELD(id,#{id_ordered.join(',')}) #{verse}") else scoped end else orig_order(args) end end |
#orig_initialize ⇒ Object
6 |
# File 'lib/ximate/activerecord/relation.rb', line 6 alias_method :orig_initialize, :initialize |
#orig_order ⇒ Object
7 |
# File 'lib/ximate/activerecord/relation.rb', line 7 alias_method :orig_order, :order |