Sha256: 945559b2a1346103a1de026d28df46463881e50248531ce936e9691d5dd30d13

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

module ActiveCollection
  module Order

    def self.included(mod)
      mod.extend ClassMethods
      mod.class_eval do
        find_scope :order_options
      end
    end

    def order
      @order ||= self.class.default_order
    end

    def order_by(order)
      ac = unloading_dup
      ac.order_by! order
      ac
    end

    def order_by!(order)
      raise_if_loaded
      @order = order
    end

    def order_options
      { :order => order } if order
    end

    module ClassMethods
      def order_by(order = "id ASC")
        write_inheritable_attribute(:default_order, order)
      end

      def default_order
        read_inheritable_attribute(:default_order) || nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_collection-0.2.4 lib/active_collection/order.rb