Class: Aws::Record::Marshalers::MapMarshaler
- Inherits:
-
Object
- Object
- Aws::Record::Marshalers::MapMarshaler
- Defined in:
- lib/aws-record/record/marshalers/map_marshaler.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MapMarshaler
constructor
A new instance of MapMarshaler.
- #serialize(raw_value) ⇒ Object
- #type_cast(raw_value) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ MapMarshaler
Returns a new instance of MapMarshaler.
7 8 9 |
# File 'lib/aws-record/record/marshalers/map_marshaler.rb', line 7 def initialize(opts = {}) # pass end |
Instance Method Details
#serialize(raw_value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aws-record/record/marshalers/map_marshaler.rb', line 28 def serialize(raw_value) map = type_cast(raw_value) if map.is_a?(Hash) map elsif map.nil? nil else msg = "expected a Hash value or nil, got #{map.class}" raise ArgumentError, msg end end |
#type_cast(raw_value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aws-record/record/marshalers/map_marshaler.rb', line 11 def type_cast(raw_value) case raw_value when nil, '' nil when Hash raw_value else if raw_value.respond_to?(:to_h) raw_value.to_h else msg = "Don't know how to make #{raw_value} of type " \ "#{raw_value.class} into a hash!" raise ArgumentError, msg end end end |