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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 379a504380d30c3c6b1c38c47661e7f366a3a6ae
4
- data.tar.gz: d7b3c58d0d7a2f4bca65d234b542e295cc4b9c56
3
+ metadata.gz: a5e8be83c9545d0ded8c76d26666c46cb7441edc
4
+ data.tar.gz: faec9a501e022c3dfc95190d6b09da1ee6725734
5
5
  SHA512:
6
- metadata.gz: 27692d7df92daba4828fb3bb122ef684e50a378b307090341e9c2ac653e42c13a329b23c1f0ee2497fe351913e6a27674e09770328cd35bc767bfe4bd8c238fa
7
- data.tar.gz: 4f8a7e8b64b3c16862fb83f02db97405c470bbbfe57464f926b94b13b17f3254ad63e963ed6b163979b577e7ac86b7203e7af382e4babd03564fa82edf414453
6
+ metadata.gz: d57c6a6e554e9cd52304c279953a1bcb09af2fb457f95c3b67e17a5485abea686abd22c90eb63dc847ce4d3e89a24cb7ad87d51b674b4cfb6dce2baf5a458038
7
+ data.tar.gz: d1605f9f38d4bf55c16cd9470d25208908612c0f82d2378255042e9f3c72fdf60882857c8fd2962f635f9231d3da09938afbe19db1bcc08d83d045b3bea59040
@@ -25,23 +25,17 @@ module Toy
25
25
  #option :access_key
26
26
  #option :secret_key
27
27
 
28
- # The default logger for Dynamoid: either the Rails logger or just stdout.
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
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Dynamo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
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.0
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-27 00:00:00.000000000 Z
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.0.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