Module: Workarea::NewDiscount

Defined in:
app/services/workarea/new_discount.rb

Class Method Summary collapse

Class Method Details

.new_discount(type, attributes) ⇒ Object



3
4
5
6
7
8
# File 'app/services/workarea/new_discount.rb', line 3

def self.new_discount(type, attributes)
  return nil unless valid_class?(type)

  klass = "Workarea::Pricing::Discount::#{type.to_s.classify}".constantize
  klass.new(attributes)
end

.valid_class?(type) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'app/services/workarea/new_discount.rb', line 10

def self.valid_class?(type)
  return false if type.to_s.blank?

  discount_class = type.to_s.demodulize.classify
  !!"Workarea::Pricing::Discount::#{discount_class}".constantize rescue false
end