Class: ActiveRecord::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/ximate/activerecord/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ranksObject

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ximate/activerecord/relation.rb', line 8

def order(*args)
  @ranks ||= {}
  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_orderObject



6
# File 'lib/ximate/activerecord/relation.rb', line 6

alias_method :orig_order, :order