toy-dynamo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5e8be83c9545d0ded8c76d26666c46cb7441edc
4
- data.tar.gz: faec9a501e022c3dfc95190d6b09da1ee6725734
3
+ metadata.gz: b009000e9ef292d89e89f980ff8696d92990f861
4
+ data.tar.gz: 29e1c1455056be654a8757834493f45c906e3ce6
5
5
  SHA512:
6
- metadata.gz: d57c6a6e554e9cd52304c279953a1bcb09af2fb457f95c3b67e17a5485abea686abd22c90eb63dc847ce4d3e89a24cb7ad87d51b674b4cfb6dce2baf5a458038
7
- data.tar.gz: d1605f9f38d4bf55c16cd9470d25208908612c0f82d2378255042e9f3c72fdf60882857c8fd2962f635f9231d3da09938afbe19db1bcc08d83d045b3bea59040
6
+ metadata.gz: 5fcef06c3655d1ad8d845616ed95b1a00d813705dd268255eb3b3109e5912fa78fc57ac715db5f505e9e9a5aa4b7be7f094acf067b9f7a3c0a01e6b37f3d1a0f
7
+ data.tar.gz: 768bef23ff4fb4cbf4298c1c9070f47ea437ff0347ddbcad253c95938c24c53e7d4c4bfa45750a9be3c21a7bca53da1ed4fac0b3af8fe879f461edce69878698
@@ -4,7 +4,7 @@ module Toy
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  # Failsafe
7
- MAX_BATCH_ITERATIONS = 1000
7
+ MAX_BATCH_ITERATIONS = 99_999
8
8
  DEFAULT_BATCH_SIZE = 100
9
9
 
10
10
  module ClassMethods
@@ -77,16 +77,16 @@ module Toy
77
77
  end
78
78
 
79
79
  #:count=>10, :scanned_count=>10, :last_evaluated_key=>{"guid"=>{:s=>"11f82550-5c5d-11e3-9b55-d311a43114ca"}}}
80
+ # :manual_batching => true|false
81
+ # return results with last_evaluated_key instead of automatically looping through (useful to throttle or )
80
82
  def scan(options={})
81
- results = dynamo_table.scan(options)
82
83
  aggregated_results = []
83
84
 
84
85
  batch_size = options.delete(:batch) || DEFAULT_BATCH_SIZE
85
86
  max_results_limit = options[:limit]
86
- if options[:limit] && options[:limit] > batch_size
87
- options.merge!(:limit => batch_size)
88
- end
87
+ options[:limit] = batch_size
89
88
 
89
+ results = dynamo_table.scan(options)
90
90
  response = Response.new(results)
91
91
 
92
92
  results[:member].each do |result|
@@ -94,7 +94,7 @@ module Toy
94
94
  aggregated_results << load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
95
95
  end
96
96
 
97
- if response.more_results?
97
+ if response.more_results? && !options[:manual_batching]
98
98
  results_returned = response.count
99
99
  batch_iteration = 0
100
100
  while response.more_results? && batch_iteration < MAX_BATCH_ITERATIONS
@@ -116,7 +116,16 @@ module Toy
116
116
  end
117
117
  end
118
118
 
119
- aggregated_results
119
+ if options[:manual_batching]
120
+ response_hash = {
121
+ :results => aggregated_results,
122
+ :last_evaluated_key => results[:last_evaluated_key]
123
+ }
124
+ response_hash.merge!(:consumed_capacity => results[:consumed_capacity]) if results[:consumed_capacity]
125
+ response_hash
126
+ else
127
+ aggregated_results
128
+ end
120
129
  end
121
130
 
122
131
  end # ClassMethods
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Dynamo
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toy-dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cary Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler