Class: Accountability::Types::BillingConfigurationTypes::BillingAddressType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Accountability::Types::BillingConfigurationTypes::BillingAddressType
- Defined in:
- lib/accountability/types/billing_configuration_types.rb
Instance Method Summary collapse
- #cast_value(value) ⇒ Object
- #changed_in_place?(raw_old_value, new_value) ⇒ Boolean
-
#serialize(data) ⇒ Object
Only serialize the attributes that we have defined and keep extraneous things like “errors” or “validation_context” from slipping into the database.
- #type ⇒ Object
Instance Method Details
#cast_value(value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/accountability/types/billing_configuration_types.rb', line 24 def cast_value(value) case value when String decoded_value = ActiveSupport::JSON.decode(value) BillingAddress.new(decoded_value) when Hash BillingAddress.new(value) when BillingAddress value end end |
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
51 52 53 |
# File 'lib/accountability/types/billing_configuration_types.rb', line 51 def changed_in_place?(raw_old_value, new_value) cast_value(raw_old_value) != new_value end |
#serialize(data) ⇒ Object
Only serialize the attributes that we have defined and keep extraneous things like “errors” or “validation_context” from slipping into the database.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/accountability/types/billing_configuration_types.rb', line 39 def serialize(data) case data when Hash billing_address = BillingAddress.new(data) ActiveSupport::JSON.encode(billing_address.attributes) when BillingAddress ActiveSupport::JSON.encode(data.attributes) else super(data) end end |
#type ⇒ Object
20 21 22 |
# File 'lib/accountability/types/billing_configuration_types.rb', line 20 def type :text end |