app/models/reserve.rb in enju_circulation-0.1.0.pre38 vs app/models/reserve.rb in enju_circulation-0.1.0.pre39
- old
+ new
@@ -6,20 +6,20 @@
attr_accessible :manifestation_id, :item_identifier, :user_number,
:expired_at, :request_status_type, :canceled_at, :checked_out_at,
:expiration_notice_to_patron, :expiration_notice_to_library, :item_id,
:retained_at, :postponed_at, :force_retaining,
as: :admin
- scope :hold, where('item_id IS NOT NULL')
- scope :not_hold, where(item_id: nil)
+ scope :hold, -> { where('item_id IS NOT NULL') }
+ scope :not_hold, -> { where(item_id: nil) }
scope :waiting, -> {not_in_state(:completed, :expired).where('canceled_at IS NULL AND expired_at > ?', Time.zone.now).order('reserves.id DESC')}
scope :retained, -> {in_state(:retained).where('retained_at IS NOT NULL')}
scope :completed, -> {in_state(:completed).where('checked_out_at IS NOT NULL')}
scope :canceled, -> {in_state(:canceled).where('canceled_at IS NOT NULL')}
scope :postponed, -> {in_state(:postponed).where('postponed_at IS NOT NULL')}
scope :will_expire_retained, lambda {|datetime| in_state(:retained).where('checked_out_at IS NULL AND canceled_at IS NULL AND expired_at <= ?', datetime).order('expired_at')}
scope :will_expire_pending, lambda {|datetime| in_state(:pending).where('checked_out_at IS NULL AND canceled_at IS NULL AND expired_at <= ?', datetime).order('expired_at')}
- scope :created, lambda {|start_date, end_date| {conditions: ['created_at >= ? AND created_at < ?', start_date, end_date]}}
+ scope :created, lambda {|start_date, end_date| where('created_at >= ? AND created_at < ?', start_date, end_date)}
scope :not_sent_expiration_notice_to_patron, -> {in_state(:expired).where(:expiration_notice_to_patron => false)}
scope :not_sent_expiration_notice_to_library, -> {in_state(:expired).where(:expiration_notice_to_library => false)}
scope :sent_expiration_notice_to_patron, -> {in_state(:expired).where(:expiration_notice_to_patron => true)}
scope :sent_expiration_notice_to_library, -> {in_state(:expired).where(:expiration_notice_to_library => true)}
scope :not_sent_cancel_notice_to_patron, -> {in_state(:canceled).where(:expiration_notice_to_patron => false)}
@@ -29,35 +29,35 @@
belongs_to :librarian, class_name: 'User'
belongs_to :item, touch: true
belongs_to :request_status_type
validates_associated :user, :librarian, :request_status_type
- validates :manifestation, :associated => true #, on: :create
+ validates :manifestation, associated: true #, on: :create
validates_presence_of :user, :request_status_type
- validates :manifestation, presence: true, :unless => Proc.new{|reserve|
+ validates :manifestation, presence: true, unless: Proc.new{|reserve|
reserve.completed?
}
#validates_uniqueness_of :manifestation_id, scope: :user_id
validates_date :expired_at, allow_blank: true
validate :manifestation_must_include_item
validate :available_for_reservation?, on: :create
- validates :item_id, presence: true, :if => Proc.new{|reserve|
+ validates :item_id, presence: true, if: Proc.new{|reserve|
if item_id_changed?
if reserve.completed? or reserve.retained?
unless item_id_change[0]
- return false
+ false
else
unless item_id_change[1]
- return false
+ false
else
- return true
+ true
end
end
end
else
if reserve.retained?
- return true
+ true
end
end
}
validate :valid_item?
validate :retained_by_other_user?
@@ -161,11 +161,11 @@
end
end
def next_reservation
if item
- Reserve.waiting.where(:manifestation_id => item.manifestation.id).readonly(false).first
+ Reserve.waiting.where(manifestation_id: item.manifestation.id).readonly(false).first
end
end
def send_message(sender = nil)
sender = User.find(1) unless sender # TODO: システムからのメッセージの発信者
@@ -315,17 +315,17 @@
false
end
private
def do_request
- self.assign_attributes({:request_status_type => RequestStatusType.where(name: 'In Process').first, item_id: nil, :retained_at => nil}, as: :admin)
+ self.assign_attributes({request_status_type: RequestStatusType.where(name: 'In Process').first, item_id: nil, retained_at: nil}, as: :admin)
save!
end
def retain
# TODO: 「取り置き中」の状態を正しく表す
- self.assign_attributes({:request_status_type => RequestStatusType.where(name: 'In Process').first, :retained_at => Time.zone.now}, as: :admin)
+ self.assign_attributes({request_status_type: RequestStatusType.where(name: 'In Process').first, retained_at: Time.zone.now}, as: :admin)
Reserve.transaction do
if item.try(:next_reservation)
reservation = item.next_reservation
reservation.transition_to!(:postponed)
end
@@ -333,11 +333,11 @@
end
end
def expire
Reserve.transaction do
- self.assign_attributes({:request_status_type => RequestStatusType.where(name: 'Expired').first, :canceled_at => Time.zone.now}, as: :admin)
+ self.assign_attributes({request_status_type: RequestStatusType.where(name: 'Expired').first, canceled_at: Time.zone.now}, as: :admin)
reserve = next_reservation
if reserve
reserve.item = item
self.item = nil
save!
@@ -347,11 +347,11 @@
logger.info "#{Time.zone.now} reserve_id #{self.id} expired!"
end
def cancel
Reserve.transaction do
- self.assign_attributes({:request_status_type => RequestStatusType.where(name: 'Cannot Fulfill Request').first, :canceled_at => Time.zone.now}, as: :admin)
+ self.assign_attributes({request_status_type: RequestStatusType.where(name: 'Cannot Fulfill Request').first, canceled_at: Time.zone.now}, as: :admin)
save!
reserve = next_reservation
if reserve
reserve.item = item
self.item = nil
@@ -360,19 +360,19 @@
end
end
end
def checkout
- self.assign_attributes({:request_status_type => RequestStatusType.where(name: 'Available For Pickup').first, :checked_out_at => Time.zone.now}, as: :admin)
+ self.assign_attributes({request_status_type: RequestStatusType.where(name: 'Available For Pickup').first, checked_out_at: Time.zone.now}, as: :admin)
save!
end
def postpone
self.assign_attributes({
- :request_status_type => RequestStatusType.where(name: 'In Process').first,
+ request_status_type: RequestStatusType.where(name: 'In Process').first,
item_id: nil,
- :retained_at => nil,
- :postponed_at => Time.zone.now
+ retained_at: nil,
+ postponed_at: Time.zone.now
}, as: :admin)
save!
end
def manifestation_must_include_item