Module: MoneyColumn::ActiveRecordHooks::ClassMethods
- Defined in:
- lib/money_column/active_record_hooks.rb
Instance Attribute Summary collapse
-
#money_column_options ⇒ Object
readonly
Returns the value of attribute money_column_options.
Instance Method Summary collapse
Instance Attribute Details
#money_column_options ⇒ Object (readonly)
Returns the value of attribute money_column_options.
70 71 72 |
# File 'lib/money_column/active_record_hooks.rb', line 70 def end |
Instance Method Details
#money_column(*columns, currency_column: nil, currency: nil, currency_read_only: false, coerce_null: false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/money_column/active_record_hooks.rb', line 72 def money_column(*columns, currency_column: nil, currency: nil, currency_read_only: false, coerce_null: false) ||= {} = ( currency_column: currency_column, currency: currency, currency_read_only: currency_read_only, coerce_null: coerce_null ) if [:currency_column] clear_cache_on_currency_change([:currency_column]) end columns.flatten.each do |column| column_string = column.to_s.freeze [column_string] = attribute(column_string, MoneyColumn::ActiveRecordType.new) define_method column do read_money_attribute(column_string) end define_method "#{column}=" do |money| write_money_attribute(column_string, money) end end end |