Sha256: a2ea60afc1d4c960f44a4a700f8951db535b683b7bedb8054a94b2c7cbb32af5

Contents?: true

Size: 1.72 KB

Versions: 15

Compression:

Stored size: 1.72 KB

Contents

module Shoppe
  class Order < ActiveRecord::Base
    
    # An array of all the available statuses for an order
    STATUSES = ['building', 'confirming', 'received', 'accepted', 'rejected', 'shipped']
    
    # The Shoppe::User who accepted the order
    #
    # @return [Shoppe::User]
    belongs_to :accepter, :class_name => 'Shoppe::User', :foreign_key => 'accepted_by'
    
    # The Shoppe::User who rejected the order
    #
    # @return [Shoppe::User]
    belongs_to :rejecter, :class_name => 'Shoppe::User', :foreign_key => 'rejected_by'
    
    # Validations
    validates :status, :inclusion => {:in => STATUSES}
    
    # Set the status to building if we don't have a status
    after_initialize  { self.status = STATUSES.first if self.status.blank? }
    
    # All orders which have been received
    scope :received, -> {where("received_at is not null")}
    
    # All orders which are currently pending acceptance/rejection
    scope :pending, -> { where(:status => 'received') }
    
    # All ordered ordered by their ID desending
    scope :ordered, -> { order(:id => :desc)}
    
    # Is this order still being built by the user?
    #
    # @return [Boolean]
    def building?
      self.status == 'building'
    end
  
    # Is this order in the user confirmation step?
    #
    # @return [Boolean]
    def confirming?
      self.status == 'confirming'
    end
  
    # Has this order been rejected?
    #
    # @return [Boolean]
    def rejected?
      !!self.rejected_at
    end
  
    # Has this order been accepted?
    #
    # @return [Boolean]
    def accepted?
      !!self.accepted_at
    end
  
    # Has the order been received?
    #
    # @return [Boolean]
    def received?
      !!self.received_at?
    end
  
    
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
shoppe-1.1.1 app/models/shoppe/order/states.rb
shoppe-1.1.0 app/models/shoppe/order/states.rb
shoppe-1.0.9 app/models/shoppe/order/states.rb
shoppe-1.0.8 app/models/shoppe/order/states.rb
kylekthompson-shoppe-1.0.7 app/models/shoppe/order/states.rb
shoppe-1.0.7 app/models/shoppe/order/states.rb
shoppe-1.0.6 app/models/shoppe/order/states.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/shoppe-1.0.5/app/models/shoppe/order/states.rb
shoppe-1.0.5 app/models/shoppe/order/states.rb
shoppe-1.0.3 app/models/shoppe/order/states.rb
shoppe-1.0.2 app/models/shoppe/order/states.rb
shoppe-1.0.1 app/models/shoppe/order/states.rb
shoppe-1.0.0 app/models/shoppe/order/states.rb
shoppe-0.0.21 app/models/shoppe/order/states.rb
shoppe-0.0.20 app/models/shoppe/order/states.rb