Sha256: 5c4e1ea68c9857476d5a738852cc6beb9d884070d75c26b2609fc5a626f98da4

Contents?: true

Size: 1 KB

Versions: 25

Compression:

Stored size: 1 KB

Contents

class Basket < ActiveRecord::Base
  default_scope { order('baskets.id DESC') }
  scope :will_expire, lambda {|date| where('created_at < ?', date)}
  belongs_to :user, validate: true
  has_many :accepts
  has_many :withdraws

  validates_associated :user, on: :create
  # 貸出完了後にかごのユーザidは破棄する
  validates_presence_of :user, on: :create
  validate :check_suspended

  attr_accessor :user_number

  def check_suspended
    if user
      errors[:base] << I18n.t('basket.this_account_is_suspended') if user.locked_at
    else
      errors[:base] << I18n.t('user.not_found')
    end
  end

  def self.expire
    Basket.will_expire(Time.zone.now.beginning_of_day).destroy_all
    logger.info "#{Time.zone.now} baskets expired!"
  end
end

# == Schema Information
#
# Table name: baskets
#
#  id           :integer          not null, primary key
#  user_id      :integer
#  note         :text
#  lock_version :integer          default(0), not null
#  created_at   :datetime
#  updated_at   :datetime
#

Version data entries

25 entries across 23 versions & 2 rubygems

Version Path
enju_library-0.3.3 app/models/basket.rb
enju_library-0.3.2 app/models/basket.rb
enju_library-0.3.1 app/models/basket.rb
enju_library-0.3.0 app/models/basket.rb
enju_library-0.3.0.rc.1 app/models/basket.rb
enju_library-0.3.0.beta.2 app/models/basket.rb
enju_library-0.2.5 app/models/basket.rb
enju_library-0.2.4 app/models/basket.rb
enju_library-0.2.3 app/models/basket.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/bundler/gems/enju_library-d36f415e177e/app/models/basket.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/enju_library-0.2.1/app/models/basket.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/enju_library-0.2.2/app/models/basket.rb
enju_library-0.2.2 app/models/basket.rb
enju_library-0.2.1 app/models/basket.rb
enju_library-0.2.0 app/models/basket.rb
enju_library-0.2.0.beta.10 app/models/basket.rb
enju_library-0.2.0.beta.9 app/models/basket.rb
enju_library-0.2.0.beta.8 app/models/basket.rb
enju_library-0.2.0.beta.7 app/models/basket.rb
enju_library-0.2.0.beta.6 app/models/basket.rb