module ActsAsHoldable::Holdable

Private Class Methods

holdable?() click to toggle source
# File lib/acts_as_holdable/holdable.rb, line 30
def self.holdable?
  true
end

Public Instance Methods

acts_as_holdable(options = {}) click to toggle source
# File lib/acts_as_holdable/holdable.rb, line 9
def acts_as_holdable(options = {})
  holdable(options)
end
holdable?() click to toggle source
# File lib/acts_as_holdable/holdable.rb, line 5
def holdable?
  false
end

Private Instance Methods

holdable(options) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/acts_as_holdable/holdable.rb, line 16
def holdable(options)
  if holdable?
    self.holding_opts = options
  else
    class_attribute :holding_opts
    self.holding_opts = options

    class_eval do
      has_many :holdings, as: :holdable, dependent: :destroy, class_name: '::ActsAsHoldable::Holding'

      validates :on_hand, presence: true, if: :on_hand_required?,
                          numericality: { only_integer: true,
                                          greater_than_or_equal_to: 0 }

      def self.holdable?
        true
      end

      def on_hand_required?
        holding_opts && holding_opts[:on_hand_type] != :none
      end
    end
  end

  include Core
end
on_hand_required?() click to toggle source
# File lib/acts_as_holdable/holdable.rb, line 34
def on_hand_required?
  holding_opts && holding_opts[:on_hand_type] != :none
end