Skip to content

Commit

Permalink
Merge pull request #788 from wal/symbols_as_strings_attribute_value
Browse files Browse the repository at this point in the history
Marshall ruby Symbols as Strings for attribute values
  • Loading branch information
trevorrowe committed Jul 22, 2015
2 parents ab0f7f5 + dbd3b72 commit c4fa8b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def format(obj)
list[:l] << format(value)
end
when String then { s: obj }
when Symbol then { s: obj.to_s }
when Numeric then { n: obj.to_s }
when StringIO, IO then { b: obj }
when Set then format_set(obj)
Expand All @@ -49,7 +50,7 @@ def format(obj)

def format_set(set)
case set.first
when String then { ss: set.map(&:to_s) }
when String, Symbol then { ss: set.map(&:to_s) }
when Numeric then { ns: set.map(&:to_s) }
when StringIO, IO then { bs: set.to_a }
else
Expand Down
9 changes: 9 additions & 0 deletions aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ module DynamoDB
expect(formatted).to eq(ss: %w(abc mno))
end

it 'converts symbol sets to :ss (string set)' do
formatted = value.marshal(Set.new([:abc, :mno]))
expect(formatted).to eq(ss: %w(abc mno))
end

it 'converts numeric sets to :ns (number set)' do
formatted = value.marshal(Set.new([123, 456]))
expect(formatted).to eq(ns: %w(123 456))
Expand All @@ -59,6 +64,10 @@ module DynamoDB
expect(value.marshal('abc')).to eq(s: 'abc')
end

it 'converts symbol to :s' do
expect(value.marshal(:abc)).to eq(s: 'abc')
end

it 'converts booleans :bool' do
# supports both true and false
expect(value.marshal(true)).to eq(bool: true)
Expand Down

0 comments on commit c4fa8b6

Please sign in to comment.