Module: CheckOut::ClassMethods
- Defined in:
- lib/check_out.rb
Instance Method Summary collapse
- #check_out_all(user) ⇒ Object (also: #check_out_all_to)
- #release_all_checkouts(user = nil) ⇒ Object (also: #release_all_checkouts_from)
Instance Method Details
#check_out_all(user) ⇒ Object Also known as: check_out_all_to
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/check_out.rb', line 37 def check_out_all(user) ids = select("#{table_name}.id").map(&:id) unscoped do where(id: ids). update_all( checked_out_by_user_id: user.id, checked_out_by_user_type: user.class.name, checked_out_at: Time.zone.now ) end unless ids.empty? end |
#release_all_checkouts(user = nil) ⇒ Object Also known as: release_all_checkouts_from
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/check_out.rb', line 51 def release_all_checkouts(user=nil) if user ids = select("#{table_name}.id").where( checked_out_by_user_id: user.id, checked_out_by_user_type: user.class.name ).map(&:id) else ids = select("#{table_name}.id").checked_out.map(&:id) end unscoped do changes = { checked_out_by_user_id: nil, checked_out_by_user_type: nil, checked_out_at: nil } where(id: ids).update_all(changes) end unless ids.empty? end |