Class: Mint::MintMoneyType
- Inherits:
-
ActiveRecord::Type::Value
- Object
- ActiveRecord::Type::Value
- Mint::MintMoneyType
- Defined in:
- lib/minting/money_attribute/money_type.rb
Overview
MintMoneyType
Class Method Summary collapse
Instance Method Summary collapse
- #assert_valid_value(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(currency:) ⇒ MintMoneyType
constructor
A new instance of MintMoneyType.
- #serialize(value) ⇒ Object
Constructor Details
#initialize(currency:) ⇒ MintMoneyType
Returns a new instance of MintMoneyType.
6 7 8 9 |
# File 'lib/minting/money_attribute/money_type.rb', line 6 def initialize(currency:) @currency = Mint.currency currency super() end |
Class Method Details
.type ⇒ Object
33 34 35 |
# File 'lib/minting/money_attribute/money_type.rb', line 33 def self.type :mint_type end |
Instance Method Details
#assert_valid_value(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/minting/money_attribute/money_type.rb', line 11 def assert_valid_value(value) case value when Numeric, String return when Mint::Money return if value.currency == @currency = "'#{value.inspect}' has different currency. Only #{@currency.code} allowed." else = "'#{value}' is not a valid type for the attribute." end raise ArgumentError, end |
#deserialize(value) ⇒ Object
25 26 27 |
# File 'lib/minting/money_attribute/money_type.rb', line 25 def deserialize(value) value && Mint.money(value, @currency) end |
#serialize(value) ⇒ Object
29 30 31 |
# File 'lib/minting/money_attribute/money_type.rb', line 29 def serialize(value) value.to_d end |