class ActsAsHoldable::Holding

Holding model. Store in host database holdings made by holders on holdables

Public Instance Methods

on_hold_required?() click to toggle source
# File lib/acts_as_holdable/holding.rb, line 27
def on_hold_required?
  holdable.holding_opts && holdable.holding_opts[:on_hold_track] != false
end
update_on_hold() click to toggle source
# File lib/acts_as_holdable/holding.rb, line 22
def update_on_hold
  holdable.update(on_hold: holdable.holdings.sum(:amount)) if holdable.respond_to?(:on_hold)
  holdable.reload
end

Private Instance Methods

holdable_is_holdable() click to toggle source

Validation method. Check if the holded model is actually holdable

# File lib/acts_as_holdable/holding.rb, line 34
def holdable_is_holdable
  return unless holdable.present? && !holdable.class.holdable?
  errors.add(:holdable, T.er('holding.must_be_holdable',
                             model: holdable.class.to_s))
end
holder_is_holder() click to toggle source

Validation method. Check if the holder model is actually a holder

# File lib/acts_as_holdable/holding.rb, line 41
def holder_is_holder
  return unless holder.present? && !holder.class.holder?
  errors.add(:holder, T.er('holder.must_be_holder',
                           model: holder.class.to_s))
end