Sha256: 1b352f0fb3e32a04e6eb21d680c3804f75af8fa3d9fc2c3ca32fedda81503acb

Contents?: true

Size: 1.72 KB

Versions: 3

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
    before_validation { self.status = 'building' 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

3 entries across 3 versions & 1 rubygems

Version Path
shoppe-0.0.19 app/models/shoppe/order/states.rb
shoppe-0.0.18 app/models/shoppe/order/states.rb
shoppe-0.0.17 app/models/shoppe/order/states.rb