module ShippingMaterials::Sortable

Attributes

sorters[RW]

Public Instance Methods

sort(context=:objects, &block) click to toggle source

DSL method

# File lib/shipping_materials/mixins/sortable.rb, line 6
def sort(context=:objects, &block)
  @sorters ||= {}
  @sorters[context] = Sorter.new
  @sorters[context].instance_eval(&block)
end
sort!() click to toggle source

Perform the sort

# File lib/shipping_materials/mixins/sortable.rb, line 13
def sort!
  @sorters.each do |context, sorter|
    @objects = if context == :objects
      sorter.sort(@objects)
    else
      @objects.each do |object|
        object.send(:"#{context}=", sorter.sort(object.send(context)))
      end
    end
  end
  @objects
end