Class: Eventsimple::MetadataType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Eventsimple::MetadataType
- Defined in:
- lib/eventsimple/metadata_type.rb
Instance Method Summary collapse
- #cast_value(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(event_class) ⇒ MetadataType
constructor
A new instance of MetadataType.
- #metadata_klass ⇒ Object
- #serialize(value) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(event_class) ⇒ MetadataType
Returns a new instance of MetadataType.
5 6 7 8 |
# File 'lib/eventsimple/metadata_type.rb', line 5 def initialize(event_class) super() @event_class = event_class end |
Instance Method Details
#cast_value(value) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/eventsimple/metadata_type.rb', line 18 def cast_value(value) case value when String decoded = ActiveSupport::JSON.decode(value) return decoded if decoded.empty? .new(decoded) when Hash .new(value) when value end end |
#deserialize(value) ⇒ Object
41 42 43 44 45 |
# File 'lib/eventsimple/metadata_type.rb', line 41 def deserialize(value) decoded = ActiveSupport::JSON.decode(value) .new(decoded) end |
#metadata_klass ⇒ Object
14 15 16 |
# File 'lib/eventsimple/metadata_type.rb', line 14 def ||= @event_class. end |
#serialize(value) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/eventsimple/metadata_type.rb', line 32 def serialize(value) case value when Hash, ActiveSupport::JSON.encode(value) else super end end |
#type ⇒ Object
10 11 12 |
# File 'lib/eventsimple/metadata_type.rb', line 10 def type :metadata_type end |