From e3fe6b06d2ea6d32c64bb5db8528a6b8cf71c332 Mon Sep 17 00:00:00 2001 From: vaughanbrittonsage Date: Thu, 27 Apr 2017 12:57:02 +0100 Subject: [PATCH] updated repository to return indifferent hashes for items --- dynamodb_framework.gemspec | 2 +- lib/dynamodb_framework/dynamodb_repository.rb | 4 ++++ lib/dynamodb_framework/hash_helper.rb | 8 ++++---- lib/dynamodb_framework/version.rb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dynamodb_framework.gemspec b/dynamodb_framework.gemspec index 621ad72..001d453 100644 --- a/dynamodb_framework.gemspec +++ b/dynamodb_framework.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency 'rspec' spec.add_development_dependency 'pry' - spec.add_dependency 'hash_kit' + spec.add_dependency 'hash_kit', '~> 0.5' spec.add_dependency 'json' spec.add_dependency 'aws-sdk-core' end diff --git a/lib/dynamodb_framework/dynamodb_repository.rb b/lib/dynamodb_framework/dynamodb_repository.rb index dfa6585..7f97df7 100644 --- a/lib/dynamodb_framework/dynamodb_repository.rb +++ b/lib/dynamodb_framework/dynamodb_repository.rb @@ -83,6 +83,7 @@ def get_by_key(partition_key, partition_value, range_key = nil, range_value = ni } result = dynamodb.client.get_item(params) + hash_helper.hash_kit.indifferent!(result.item) return result.item end @@ -95,6 +96,7 @@ def all output = [] result.items.each do |item| + hash_helper.hash_kit.indifferent!(item) output.push(item) end @@ -144,6 +146,7 @@ def scan(expression, expression_params, limit = nil, count = false) else output = [] result.items.each do |item| + hash_helper.hash_kit.indifferent!(item) output.push(item) end @@ -204,6 +207,7 @@ def query(partition_key_name, partition_key_value, range_key_name = nil, range_k else output = [] result.items.each do |item| + hash_helper.hash_kit.indifferent!(item) output.push(item) end diff --git a/lib/dynamodb_framework/hash_helper.rb b/lib/dynamodb_framework/hash_helper.rb index b116db9..cec112e 100644 --- a/lib/dynamodb_framework/hash_helper.rb +++ b/lib/dynamodb_framework/hash_helper.rb @@ -5,6 +5,10 @@ def to_hash(obj) strip_nil(hsh) end + def hash_kit + @hash_kit ||= HashKit::Helper.new + end + private def strip_nil(obj) @@ -15,9 +19,5 @@ def strip_nil(obj) end obj.delete_if(&remove_nil) end - - def hash_kit - @hash_kit ||= HashKit::Helper.new - end end end diff --git a/lib/dynamodb_framework/version.rb b/lib/dynamodb_framework/version.rb index 3cd78d8..4708c0f 100644 --- a/lib/dynamodb_framework/version.rb +++ b/lib/dynamodb_framework/version.rb @@ -1,3 +1,3 @@ module DynamoDbFramework - VERSION = '1.4.0' + VERSION = '1.4.1' end