Class: ActiveMapper::Adapter::Memory::Order::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mapper/adapter/memory/order/attribute.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Attribute

Returns a new instance of Attribute.



6
7
8
9
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 6

def initialize(name)
  @name = name
  @direction = :asc
end

Instance Method Details

#-@Object



11
12
13
14
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 11

def -@
  @direction = :desc
  self
end

#reverseObject



16
17
18
19
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 16

def reverse
  @direction = asc? ? :desc : :asc
  self
end

#to_procObject



21
22
23
24
25
26
27
28
29
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 21

def to_proc
  proc do |x,y|
    if asc?
      x.send(@name) <=> y.send(@name)
    else
      y.send(@name) <=> x.send(@name)
    end
  end
end