Module: EasyRailsMoney::ActiveRecord::Migration::TableDefinition
- Defined in:
- lib/easy_rails_money/active_record/migration/table_definition.rb
Instance Method Summary collapse
-
#currency(options = {}) ⇒ Object
Adds a common currency column.
-
#money(column_names, options = {}) ⇒ Object
Creates one or two columns to represent a Money object in the named table.
Instance Method Details
#currency(options = {}) ⇒ Object
Adds a common currency column
Usually we create an currency column for each money columns. We can have multiple money columns in the same record, in which case we can have a single currency column. This helper creates that common curremcy column
17 18 19 20 |
# File 'lib/easy_rails_money/active_record/migration/table_definition.rb', line 17 def currency ={} remove_currency_columns column :currency, :string, end |
#money(column_names, options = {}) ⇒ Object
If we have defined a currency column for a record then only the integer column is defined.
Creates one or two columns to represent a Money object in the named table
An integer column for storing Money in its base unit eg. cents for a Dollar denomination and a string for storing its currency name. Can think of it as a persisted or serialized Money object in the database. The integer column is suffixed with ‘_money’ to aid in reflection ie. to find all money columns. Likewise the currency column is suffixed with ‘_currency’ If does not create an individual currency column if a common currency column is defined
41 42 43 44 45 46 47 48 |
# File 'lib/easy_rails_money/active_record/migration/table_definition.rb', line 41 def money(column_names, ={}) Array(column_names).each do |name| column "#{name}_money", :integer, unless columns.select { |x| x.name == "currency" }.any? column "#{name}_currency", :string, end end end |