Module: ActsAsHoldable::Holdable::Core::InstanceMethods
- Defined in:
- lib/acts_as_holdable/holdable/core.rb
Instance Method Summary collapse
- #be_held!(holder, opts = {}) ⇒ Object
- #check_availability(opts) ⇒ Object
- #check_availability!(opts) ⇒ Object
- #hold!(holder, opts) ⇒ Object
- #holder? ⇒ Boolean
- #validate_holding_options!(opts) ⇒ Object
Instance Method Details
#be_held!(holder, opts = {}) ⇒ Object
118 119 120 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 118 def be_held!(holder, opts={}) holder.hold!(self, opts) end |
#check_availability(opts) ⇒ Object
112 113 114 115 116 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 112 def check_availability(opts) check_availability!(opts) rescue ActsAsHoldable::AvailabilityError false end |
#check_availability!(opts) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 98 def check_availability!(opts) # validates options (opts) if holding_opts[:on_hand_type] != :none # Amount > on_hand if opts[:amount] > on_hand raise ActsAsHoldable::AvailabilityError, ActsAsHoldable::T.er('.availability.amount_gt_on_hand', model: self.class.to_s) end end true end |
#hold!(holder, opts) ⇒ Object
122 123 124 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 122 def hold!(holder, opts) holder.hold(self, opts) end |
#holder? ⇒ Boolean
130 131 132 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 130 def holder? self.class.holder? end |
#validate_holding_options!(opts) ⇒ Object
126 127 128 |
# File 'lib/acts_as_holdable/holdable/core.rb', line 126 def (opts) self.class.(opts) end |