Class: Eventsimple::DataType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Eventsimple::DataType
- Defined in:
- lib/eventsimple/data_type.rb
Instance Attribute Summary collapse
-
#event_klass ⇒ Object
readonly
Returns the value of attribute event_klass.
Instance Method Summary collapse
- #cast_value(value) ⇒ Object
- #changed_in_place?(raw_old_value, new_value) ⇒ Boolean
- #deserialize(value) ⇒ Object
-
#initialize(event_klass) ⇒ DataType
constructor
A new instance of DataType.
- #mutable? ⇒ Boolean
- #serialize(value) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(event_klass) ⇒ DataType
Returns a new instance of DataType.
5 6 7 8 |
# File 'lib/eventsimple/data_type.rb', line 5 def initialize(event_klass) @event_klass = event_klass super() end |
Instance Attribute Details
#event_klass ⇒ Object (readonly)
Returns the value of attribute event_klass.
10 11 12 |
# File 'lib/eventsimple/data_type.rb', line 10 def event_klass @event_klass end |
Instance Method Details
#cast_value(value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/eventsimple/data_type.rb', line 16 def cast_value(value) case value when String decoded = ActiveSupport::JSON.decode(value) prepare_data(decoded) when Hash prepare_data(value) when value end end |
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
47 48 49 50 |
# File 'lib/eventsimple/data_type.rb', line 47 def changed_in_place?(raw_old_value, new_value) old_value = deserialize(raw_old_value) old_value != new_value end |
#deserialize(value) ⇒ Object
41 42 43 44 45 |
# File 'lib/eventsimple/data_type.rb', line 41 def deserialize(value) decoded = ActiveSupport::JSON.decode(value) decrypted_data = (decoded) ? .new(decrypted_data) : decrypted_data end |
#mutable? ⇒ Boolean
52 53 54 |
# File 'lib/eventsimple/data_type.rb', line 52 def mutable? true end |
#serialize(value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eventsimple/data_type.rb', line 28 def serialize(value) case value when Hash encrypted_data = (value) ActiveSupport::JSON.encode(encrypted_data) when event_klass::Message encrypted_data = (value.attributes) ActiveSupport::JSON.encode(encrypted_data) else super end end |
#type ⇒ Object
12 13 14 |
# File 'lib/eventsimple/data_type.rb', line 12 def type :data_type end |