Class: Accountability::Types::BillingConfigurationTypes::BillingAddressType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/accountability/types/billing_configuration_types.rb

Instance Method Summary collapse

Instance Method Details

#cast_value(value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/accountability/types/billing_configuration_types.rb', line 32

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

Returns:

  • (Boolean)


59
60
61
# File 'lib/accountability/types/billing_configuration_types.rb', line 59

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.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/accountability/types/billing_configuration_types.rb', line 47

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

#typeObject



28
29
30
# File 'lib/accountability/types/billing_configuration_types.rb', line 28

def type
  :text
end