lotus-dynamodb 0.1.1 → 0.1.2

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: 4afda395af46d537deed3ac0619746f3c693f53b
4
- data.tar.gz: f4c3028928436d9c3d035e48a8ec7a17dab6137c
3
+ metadata.gz: 4a025c678317bce959cb08e9fe84d43e17ee8b0f
4
+ data.tar.gz: 408402f20f9a9e9e523039df3e43114732aa013a
5
5
  SHA512:
6
- metadata.gz: f35e5aa974d0cb68835e04f6fc6e4b7e77d87f8239ef13a84f5acdf23e6c927d2b1e468d67bf19f82854755cc94e119073b13fb4e16bd0f493668a8eb08395e8
7
- data.tar.gz: 0d2fea387a98192508cda33c444500374ba1cfe4ff5a2b5b157ecaf1d75e84c4519ec8e8002dffbc84c75a0de6311c0a514f439996f7971173881fcdd3ffdee9
6
+ metadata.gz: 0863ca668599f711306a9a0c144a52b69f0e42f89b4b6397a86797a13fb5111c2f0b52346627ec59bab791707e4dd6c7fd9865f081706c4cd69de4e418da3f2b
7
+ data.tar.gz: 17ea2d92690e352a795bb6ccc23fb5cfecc6b7422cc6af583f12f5bb663d85baedf00e3c35d674455d4f602ed5e4a865d5b7e548635982b89c923666fb499239
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.1.2
2
+ ------
3
+
4
+ * Make Collection#update respect nil attributes
5
+ * Fix continuation & limit bug
6
+
1
7
  v0.1.1
2
8
  ------
3
9
 
@@ -3,6 +3,6 @@ module Lotus
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '0.1.1'
6
+ VERSION = '0.1.2'
7
7
  end
8
8
  end
@@ -248,7 +248,9 @@ module Lotus
248
248
  # @api private
249
249
  # @since 0.1.0
250
250
  def serialize_item(record)
251
- Hash[record.map { |k, v| [k.to_s, format_attribute_value(v)] }]
251
+ Hash[record.delete_if { |_, v| v.nil? }.map do |k, v|
252
+ [k.to_s, format_attribute_value(v)]
253
+ end]
252
254
  end
253
255
 
254
256
  # Serialize given record or primary key to have proper attributes
@@ -282,7 +284,11 @@ module Lotus
282
284
  def serialize_attributes(entity)
283
285
  keys = key_schema.keys
284
286
  Hash[entity.reject { |k, _| keys.include?(k) }.map do |k, v|
285
- [k.to_s, { value: format_attribute_value(v), action: "PUT" }]
287
+ if v.nil?
288
+ [k.to_s, { action: "DELETE" }]
289
+ else
290
+ [k.to_s, { value: format_attribute_value(v), action: "PUT" }]
291
+ end
286
292
  end]
287
293
  end
288
294
 
@@ -94,8 +94,7 @@ module Lotus
94
94
  # @api private
95
95
  # @since 0.1.0
96
96
  def _serialize(entity)
97
- serialized = @collection.serialize(entity)
98
- serialized.delete_if { |_, v| v.nil? }
97
+ @collection.serialize(entity)
99
98
  end
100
99
  end
101
100
  end
@@ -82,7 +82,8 @@ module Lotus
82
82
  # @since 0.1.0
83
83
  def all
84
84
  response = run
85
- while !@options[:limit] && response.last_evaluated_key
85
+
86
+ while continue?(response)
86
87
  @options[:exclusive_start_key] = response.last_evaluated_key
87
88
  response = run(response)
88
89
  end
@@ -97,10 +98,11 @@ module Lotus
97
98
  # @since 0.1.1
98
99
  def each
99
100
  response = run
101
+
100
102
  entities = @collection.deserialize(response.entities)
101
103
  entities.each { |x| yield(x) }
102
104
 
103
- while !@options[:limit] && response.last_evaluated_key
105
+ while continue?(response)
104
106
  response.entities = []
105
107
 
106
108
  @options[:exclusive_start_key] = response.last_evaluated_key
@@ -474,7 +476,7 @@ module Lotus
474
476
 
475
477
  response = run
476
478
 
477
- while !@options[:limit] && response.last_evaluated_key
479
+ while continue?(response)
478
480
  @options[:exclusive_start_key] = response.last_evaluated_key
479
481
  response = run(response)
480
482
  end
@@ -590,6 +592,30 @@ module Lotus
590
592
  def run(previous_response = nil)
591
593
  @dataset.public_send(operation, @options, previous_response)
592
594
  end
595
+
596
+ # Check if request needs to be continued.
597
+ #
598
+ # @param previous_response [Response] deserialized response from a previous operation
599
+ #
600
+ # @return [Boolean]
601
+ #
602
+ # @api private
603
+ # @since 0.1.2
604
+ def continue?(previous_response)
605
+ return false unless previous_response.last_evaluated_key
606
+
607
+ if @options[:limit]
608
+ if @options[:limit] > previous_response.count
609
+ @options[:limit] = @options[:limit] - previous_response.count
610
+
611
+ true
612
+ else
613
+ false
614
+ end
615
+ else
616
+ true
617
+ end
618
+ end
593
619
  end
594
620
  end
595
621
  end
@@ -146,6 +146,15 @@ describe Lotus::Model::Adapters::DynamodbAdapter do
146
146
  entity.id.must_equal id
147
147
  @adapter.find(collection, entity.id).must_equal entity
148
148
  end
149
+
150
+ it 'removes attribute' do
151
+ entity.name = nil
152
+ @adapter.update(collection, entity)
153
+
154
+ found_entity = @adapter.find(collection, entity.id)
155
+ found_entity.must_equal entity
156
+ found_entity.name.must_be_nil
157
+ end
149
158
  end
150
159
 
151
160
  describe '#delete' do
@@ -831,6 +840,33 @@ describe Lotus::Model::Adapters::DynamodbAdapter do
831
840
  result.must_equal [purchase1]
832
841
  end
833
842
  end
843
+
844
+ describe 'with large records set' do
845
+ before do
846
+ purchases.each do |entity|
847
+ @adapter.create(collection, entity)
848
+ end
849
+ end
850
+
851
+ let(:purchases) do
852
+ 25.times.map do |i|
853
+ TestPurchase.new(
854
+ region: 'europe',
855
+ content: ('A'..'Z').to_a[i]*50_000,
856
+ created_at: Time.new,
857
+ )
858
+ end
859
+ end
860
+
861
+ it 'returns all of them' do
862
+ query = Proc.new {
863
+ where(region: 'europe').limit(24)
864
+ }
865
+
866
+ result = @adapter.query(collection, &query).count
867
+ result.must_equal 24
868
+ end
869
+ end
834
870
  end
835
871
 
836
872
  describe 'exists?' do
data/test/version_test.rb CHANGED
@@ -2,6 +2,6 @@ require 'test_helper'
2
2
 
3
3
  describe Lotus::Dynamodb::VERSION do
4
4
  it 'returns current version' do
5
- Lotus::Dynamodb::VERSION.must_equal '0.1.1'
5
+ Lotus::Dynamodb::VERSION.must_equal '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotus-dynamodb
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
  - Dmitry Krasnoukhov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lotus-model