Module: ActsAsPriceable::Schema::Statements

Defined in:
lib/acts_as_priceable/schema.rb

Instance Method Summary collapse

Instance Method Details

#add_price(table_name, *price_names) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
# File 'lib/acts_as_priceable/schema.rb', line 22

def add_price(table_name, *price_names)
  raise ArgumentError, "Please specify price name in your add_price call in your migration." if price_names.empty?

  price_names.each do |price_name|
    COLUMNS.each do |column_name, column_type|
      add_column(table_name, "#{price_name}_#{column_name}", column_type)
    end
  end
end

#remove_price(table_name, *price_names) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
# File 'lib/acts_as_priceable/schema.rb', line 32

def remove_price(table_name, *price_names)
  raise ArgumentError, "Please specify price name in your remove_price call in your migration." if price_names.empty?

  price_names.each do |price_name|
    COLUMNS.each do |column_name, _|
      remove_column(table_name, "#{price_name}_#{column_name}")
    end
  end
end