Module: Amount::ActiveRecord::MigrationMethods
- Defined in:
- lib/amount/active_record/migration_methods.rb
Overview
Adds ‘t.amount` to migrations.
Multi-symbol amounts create ‘*_atomic` and `*_symbol` columns. Fixed symbol amounts create only the atomic column.
Instance Method Summary collapse
-
#amount(name, precision: 78, symbol: nil, **options) ⇒ void
Adds one amount attribute to the table definition.
Instance Method Details
#amount(name, precision: 78, symbol: nil, **options) ⇒ void
This method returns an undefined value.
Adds one amount attribute to the table definition.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/amount/active_record/migration_methods.rb', line 24 def amount(name, precision: 78, symbol: nil, **) default = .delete(:default) null = .key?(:null) ? [:null] : nil comment = [:comment] defaults = normalize_defaults(default, symbol) = { precision:, scale: 0, default: defaults[:atomic], comment: } [:null] = null unless null.nil? decimal(name_to_atomic(name), **.compact) return if symbol = { limit: 10, default: defaults[:symbol], comment: } [:null] = null unless null.nil? string(name_to_symbol(name), **.compact) end |