Module: Codecs::UnionCodec
- Defined in:
- lib/emery/codecs.rb
Class Method Summary collapse
- .applicable?(type) ⇒ Boolean
- .deserialize(type, json_value) ⇒ Object
- .serialize(type, value) ⇒ Object
Class Method Details
.applicable?(type) ⇒ Boolean
77 78 79 |
# File 'lib/emery/codecs.rb', line 77 def self.applicable?(type) type.instance_of? T::UnionType end |
.deserialize(type, json_value) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/emery/codecs.rb', line 80 def self.deserialize(type, json_value) type.types.each do |t| begin return Jsoner.deserialize(t, json_value) rescue JsonerError end end raise JsonerError.new("Value '#{json_value.inspect.to_s}' can not be deserialized as any of #{type.types.map { |t| t.to_s}.join(', ')}") end |