Class: Aws::Record::Marshalers::StringMarshaler

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-record/record/marshalers/string_marshaler.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ StringMarshaler

Returns a new instance of StringMarshaler



19
20
# File 'lib/aws-record/record/marshalers/string_marshaler.rb', line 19

def initialize(opts = {})
end

Instance Method Details

#serialize(raw_value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aws-record/record/marshalers/string_marshaler.rb', line 33

def serialize(raw_value)
  value = type_cast(raw_value)
  if value.is_a?(String)
    if value.empty?
      nil
    else
      value
    end
  elsif value.nil?
    nil
  else
    msg = "expected a String value or nil, got #{value.class}"
    raise ArgumentError, msg
  end
end

#type_cast(raw_value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/aws-record/record/marshalers/string_marshaler.rb', line 22

def type_cast(raw_value)
  case raw_value
  when nil
    nil
  when String
    raw_value
  else
    raw_value.to_s
  end
end