From dbd3b7221927bf9ea89270675893a5a5e9ff5ed6 Mon Sep 17 00:00:00 2001 From: wal Date: Wed, 22 Apr 2015 15:04:45 +0100 Subject: [PATCH] Allow Symbols as attribute values, stored as String --- .../lib/aws-sdk-core/dynamodb/attribute_value.rb | 3 ++- aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb b/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb index c8dc9a07dbc..a6d1f94c61b 100644 --- a/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb +++ b/aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb @@ -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.read } when Set then format_set(obj) @@ -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.map(&:read) } else diff --git a/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb b/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb index e0a5d6ff5bb..685377fd0b8 100644 --- a/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb +++ b/aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb @@ -31,6 +31,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)) @@ -52,6 +57,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)