toy-dynamo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toy/dynamo/config.rb +1 -7
- data/lib/toy/dynamo/querying.rb +43 -0
- data/lib/toy/dynamo/table.rb +2 -2
- data/lib/toy/dynamo/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5e8be83c9545d0ded8c76d26666c46cb7441edc
|
4
|
+
data.tar.gz: faec9a501e022c3dfc95190d6b09da1ee6725734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57c6a6e554e9cd52304c279953a1bcb09af2fb457f95c3b67e17a5485abea686abd22c90eb63dc847ce4d3e89a24cb7ad87d51b674b4cfb6dce2baf5a458038
|
7
|
+
data.tar.gz: d1605f9f38d4bf55c16cd9470d25208908612c0f82d2378255042e9f3c72fdf60882857c8fd2962f635f9231d3da09938afbe19db1bcc08d83d045b3bea59040
|
data/lib/toy/dynamo/config.rb
CHANGED
@@ -25,23 +25,17 @@ module Toy
|
|
25
25
|
#option :access_key
|
26
26
|
#option :secret_key
|
27
27
|
|
28
|
-
# The default logger
|
29
|
-
#
|
30
|
-
# @since 0.2.0
|
28
|
+
# The default logger: either the Rails logger or just stdout.
|
31
29
|
def default_logger
|
32
30
|
defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
|
33
31
|
end
|
34
32
|
|
35
33
|
# Returns the assigned logger instance.
|
36
|
-
#
|
37
|
-
# @since 0.2.0
|
38
34
|
def logger
|
39
35
|
@logger ||= default_logger
|
40
36
|
end
|
41
37
|
|
42
38
|
# If you want to, set the logger manually to any output you'd like. Or pass false or nil to disable logging entirely.
|
43
|
-
#
|
44
|
-
# @since 0.2.0
|
45
39
|
def logger=(logger)
|
46
40
|
case logger
|
47
41
|
when false, nil then @logger = nil
|
data/lib/toy/dynamo/querying.rb
CHANGED
@@ -76,6 +76,49 @@ module Toy
|
|
76
76
|
results_map
|
77
77
|
end
|
78
78
|
|
79
|
+
#:count=>10, :scanned_count=>10, :last_evaluated_key=>{"guid"=>{:s=>"11f82550-5c5d-11e3-9b55-d311a43114ca"}}}
|
80
|
+
def scan(options={})
|
81
|
+
results = dynamo_table.scan(options)
|
82
|
+
aggregated_results = []
|
83
|
+
|
84
|
+
batch_size = options.delete(:batch) || DEFAULT_BATCH_SIZE
|
85
|
+
max_results_limit = options[:limit]
|
86
|
+
if options[:limit] && options[:limit] > batch_size
|
87
|
+
options.merge!(:limit => batch_size)
|
88
|
+
end
|
89
|
+
|
90
|
+
response = Response.new(results)
|
91
|
+
|
92
|
+
results[:member].each do |result|
|
93
|
+
attrs = Response.strip_attr_types(result)
|
94
|
+
aggregated_results << load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
|
95
|
+
end
|
96
|
+
|
97
|
+
if response.more_results?
|
98
|
+
results_returned = response.count
|
99
|
+
batch_iteration = 0
|
100
|
+
while response.more_results? && batch_iteration < MAX_BATCH_ITERATIONS
|
101
|
+
if max_results_limit && (delta_results_limit = (max_results_limit-results_returned)) < batch_size
|
102
|
+
break if delta_results_limit == 0
|
103
|
+
options.merge!(:limit => delta_results_limit)
|
104
|
+
else
|
105
|
+
options.merge!(:limit => batch_size)
|
106
|
+
end
|
107
|
+
|
108
|
+
results = dynamo_table.scan(options.merge(:exclusive_start_key => response.last_evaluated_key))
|
109
|
+
response = Response.new(results)
|
110
|
+
results[:member].each do |result|
|
111
|
+
attrs = Response.strip_attr_types(result)
|
112
|
+
aggregated_results << load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
|
113
|
+
end
|
114
|
+
results_returned += response.count
|
115
|
+
batch_iteration += 1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
aggregated_results
|
120
|
+
end
|
121
|
+
|
79
122
|
end # ClassMethods
|
80
123
|
|
81
124
|
end
|
data/lib/toy/dynamo/table.rb
CHANGED
@@ -399,8 +399,8 @@ module Toy
|
|
399
399
|
scan_request.merge!(:scan_filter => scan_filter)
|
400
400
|
end
|
401
401
|
|
402
|
-
scan_request.merge!({ :segment => options[:segment] }) if options[:segment]
|
403
|
-
scan_request.merge!({ :total_segments => options[:total_segments].to_i }) if options[:total_segments]
|
402
|
+
scan_request.merge!({ :segment => options[:segment].to_i }) if options[:segment].present?
|
403
|
+
scan_request.merge!({ :total_segments => options[:total_segments].to_i }) if options[:total_segments].present?
|
404
404
|
|
405
405
|
@client.scan(scan_request)
|
406
406
|
end
|
data/lib/toy/dynamo/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.1.11
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: ActiveModel based DynamoDB ORM - extension to toystore
|