dynamosaurus 0.0.8 → 0.0.9

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: 61f38932ba6096baa0ae0952bb548637b2829640
4
- data.tar.gz: dc8455607eaad41f4c7ad2f1a8657c0f8b9770c0
3
+ metadata.gz: cf094775fd40a2513f250d77db7be0d6797f7134
4
+ data.tar.gz: 58be5bbc575faf23d73e70a60f0c778ca81859f4
5
5
  SHA512:
6
- metadata.gz: 981993c41a99915f41d1b610d19cba3af6ccb944b8f255bea5ce3965ad190a38d96aa8f4b5ba5b730f6225fa8c8dd4b6a76703d24b40f87d866bb266f5a367af
7
- data.tar.gz: 839c4eaa14d3adc3bf7d406cf8791284e5c66950313c2b25d794b8b8f0ea0275233f76e2c75a3e88def82a4f206558d17fc77b7c47a58a027ac94ecf07950c12
6
+ metadata.gz: e04ff2346be1beacadcd04505b7ab1d8d98d5a46b1a06e1c2d748715a7da15f90943dbaa5547b00bef6ef4587acb6b8ed2eb56ae46a091bc40d735fdf6c1e702
7
+ data.tar.gz: a99e63225e2772ca1320f1fccca2a1a882e13e6bcaa1834f8b5b4421607f7e27d749e7f5ec44f71d32771d6367bb943e0d5d1460fb6dd9c58ecc179aa6eb59a8
@@ -55,102 +55,156 @@ module Dynamosaurus
55
55
  @table ||= options
56
56
  end
57
57
 
58
- def key k, type, range_key=nil, range_key_type=nil
58
+ def key k, type, range_key_name=nil, range_key_type=nil
59
59
  @key = [k, Dynamosaurus::DynamoBase::TYPES[type]]
60
- @key << range_key << Dynamosaurus::DynamoBase::TYPES[range_key_type] if range_key
60
+ @key << range_key_name << Dynamosaurus::DynamoBase::TYPES[range_key_type] if range_key_name
61
61
  end
62
62
 
63
63
  def get_key
64
64
  @key
65
65
  end
66
66
 
67
- def schema
68
- @schema = {}
69
- @schema[:table_name] = table_name
70
- @schema[:key_schema] = []
71
- @schema[:attribute_definitions] = []
72
-
73
- @schema[:provisioned_throughput] = {
74
- :read_capacity_units => 10,
75
- :write_capacity_units => 10
76
- }
77
-
78
- @schema[:key_schema] << {
79
- :key_type => "HASH",
80
- :attribute_name => get_key[0].to_s
81
- }
82
- @schema[:attribute_definitions] << {:attribute_name => get_key[0].to_s, :attribute_type => get_key[1].to_s.upcase}
67
+ def has_renge
68
+ @key.size == 4
69
+ end
83
70
 
84
- if get_key.size == 4
85
- @schema[:key_schema] << {
86
- :key_type => "RANGE",
87
- :attribute_name => get_key[2].to_s
88
- }
89
- @schema[:attribute_definitions] << {:attribute_name => get_key[2].to_s, :attribute_type => get_key[3].to_s.upcase}
90
- end
71
+ def hash_key
72
+ @key[0]
73
+ end
91
74
 
92
- unless get_global_indexes.empty?
93
- @schema[:global_secondary_indexes] = []
94
- get_global_indexes.each do |g_index|
95
- index_schema = {
96
- :index_name => g_index[0],
97
- :key_schema => [],
98
- :projection => {
99
- :projection_type => "KEYS_ONLY",
100
- },
101
- :provisioned_throughput => {
102
- :read_capacity_units => 10,
103
- :write_capacity_units => 10
104
- },
105
- }
106
- index_schema[:key_schema] << {
107
- :key_type => "HASH",
108
- :attribute_name => g_index[1][0]
109
- }
110
- @schema[:attribute_definitions] << {:attribute_name => g_index[1][0].to_s, :attribute_type => g_index[1][1].to_s.upcase}
111
- if g_index[1].size == 4
112
- index_schema[:key_schema] << {
113
- :key_type => "RANGE",
114
- :attribute_name => g_index[1][2]
115
- }
116
- @schema[:attribute_definitions] << {:attribute_name => g_index[1][2].to_s, :attribute_type => g_index[1][3].to_s.upcase}
117
- end
75
+ def range_key
76
+ @key[2]
77
+ end
118
78
 
119
- @schema[:global_secondary_indexes] << index_schema
120
- end
79
+ def key_schema
80
+ key = [{
81
+ :key_type => "HASH",
82
+ :attribute_name => hash_key.to_s
83
+ }]
84
+ key << {
85
+ :key_type => "RANGE",
86
+ :attribute_name => range_key.to_s
87
+ } if has_renge
88
+ key
89
+ end
90
+
91
+ # schema
92
+ def push_attribute_definitions name, type
93
+ if @attribute_definitions.nil?
94
+ @attribute_definitions = []
95
+ @attribute_names = []
121
96
  end
122
- unless get_secondary_indexes.empty?
123
- @schema[:local_secondary_indexes] = []
124
- get_secondary_indexes.each do |s_index_key, s_index_value|
125
- index_schema = {
126
- :index_name => s_index_key,
127
- :key_schema => [],
128
- :projection => {
129
- :projection_type => "KEYS_ONLY",
130
- },
131
- }
132
- index_schema[:key_schema] =[
97
+ if @attribute_names.index(name).nil?
98
+ @attribute_definitions << {:attribute_name => name, :attribute_type => type}
99
+ @attribute_names << name
100
+ end
101
+ end
102
+ def set_init_attribute_definitions
103
+ push_attribute_definitions(hash_key.to_s, get_key[1].to_s.upcase)
104
+ push_attribute_definitions(range_key.to_s, get_key[3].to_s.upcase) if has_renge
105
+ end
106
+ def attribute_definitions
107
+ @attribute_definitions
108
+ end
109
+
110
+ def local_secondary_schemas
111
+ schema = []
112
+ get_secondary_indexes.each do |index_key, index_value|
113
+ schema << {
114
+ index_name: index_key,
115
+ key_schema: [],
116
+ projection: {
117
+ projection_type: "KEYS_ONLY",
118
+ },
119
+ key_schema: [
133
120
  {
134
- :key_type => "HASH",
135
- :attribute_name => s_index_value[0]
121
+ key_type: "HASH",
122
+ attribute_name: index_value[0]
136
123
  },
137
124
  {
138
- :key_type => "RANGE",
139
- :attribute_name => s_index_value[2]
125
+ key_type: "RANGE",
126
+ attribute_name: index_value[2]
140
127
  }
141
128
  ]
142
- @schema[:attribute_definitions] << {:attribute_name => s_index_value[2].to_s, :attribute_type => s_index_value[3].to_s.upcase}
143
- @schema[:local_secondary_indexes] << index_schema
144
- end
129
+ }
130
+ end
131
+ schema
132
+ end
133
+
134
+ def global_index_schemas
135
+ schema = []
136
+ get_global_indexes.each do |index|
137
+ schema << {
138
+ :index_name => index[0],
139
+ :key_schema => global_index_key_schema(index),
140
+ :projection => {
141
+ :projection_type => "KEYS_ONLY",
142
+ },
143
+ :provisioned_throughput => {
144
+ :read_capacity_units => 10,
145
+ :write_capacity_units => 10
146
+ }
147
+ }
148
+ end
149
+ schema
150
+ end
151
+
152
+ def global_index_key_schema index
153
+ key_schema = [{
154
+ :key_type => "HASH",
155
+ :attribute_name => index[1][0]
156
+ }]
157
+ key_schema << {
158
+ :key_type => "RANGE",
159
+ :attribute_name => index[1][2]
160
+ } if index[1].size == 4
161
+ key_schema
162
+ end
163
+
164
+ def local_secondary_attribute_definitions
165
+ get_secondary_indexes.each do |index_key, index_value|
166
+ push_attribute_definitions(index_value[2].to_s, index_value[3].to_s.upcase)
145
167
  end
168
+ end
169
+
170
+ def global_indexes_attribute_definitions
171
+ get_global_indexes.each do |index|
172
+ push_attribute_definitions(index[1][0].to_s, index[1][1].to_s.upcase)
173
+ push_attribute_definitions(index[1][2].to_s, index[1][3].to_s.upcase) if index[1].size == 4
174
+ end
175
+ end
176
+
177
+ def schema
178
+ set_init_attribute_definitions
179
+
180
+ @schema = {
181
+ table_name: table_name,
182
+ key_schema: key_schema,
183
+ provisioned_throughput: {
184
+ read_capacity_units: 10,
185
+ write_capacity_units: 10
186
+ }
187
+ }
188
+
189
+ unless get_global_indexes.empty?
190
+ @schema[:global_secondary_indexes] = global_index_schemas
191
+ global_indexes_attribute_definitions
192
+ end
193
+ unless get_secondary_indexes.empty?
194
+ @schema[:local_secondary_indexes] = local_secondary_schemas
195
+ local_secondary_attribute_definitions
196
+ end
197
+ @schema[:attribute_definitions] = attribute_definitions
146
198
 
147
199
  @schema
148
200
  end
201
+ # end of schema
149
202
 
150
- def global_index index_name, key, key_type, range_key=nil, range_key_type=nil
203
+ # indexes
204
+ def global_index index_name, key, key_type, range_key_name=nil, range_key_type=nil
151
205
  @global_index = {} if @global_index.nil?
152
206
  @global_index[index_name] = [key, Dynamosaurus::DynamoBase::TYPES[key_type]]
153
- @global_index[index_name] << range_key << Dynamosaurus::DynamoBase::TYPES[range_key_type] if range_key
207
+ @global_index[index_name] << range_key_name << Dynamosaurus::DynamoBase::TYPES[range_key_type] if range_key_name
154
208
  end
155
209
 
156
210
  def get_global_indexes
@@ -161,9 +215,9 @@ module Dynamosaurus
161
215
  @global_index[name]
162
216
  end
163
217
 
164
- def secondary_index index_name, range_key=nil, range_key_type=nil
218
+ def secondary_index index_name, range_key_name=nil, range_key_type=nil
165
219
  @secondary_index = {} if @secondary_index.nil?
166
- @secondary_index[index_name.to_sym] = [@key[0], @key[1], range_key, Dynamosaurus::DynamoBase::TYPES[range_key_type]] if range_key
220
+ @secondary_index[index_name.to_sym] = [@key[0], @key[1], range_key_name, Dynamosaurus::DynamoBase::TYPES[range_key_type]] if range_key_name
167
221
  end
168
222
 
169
223
  def get_secondary_indexes
@@ -193,28 +247,19 @@ module Dynamosaurus
193
247
  }
194
248
  nil
195
249
  end
250
+ # end of indexes
196
251
 
197
252
  def table_prefix name
198
253
  @table_prefix = name
199
254
  end
200
255
 
201
- def key_list
202
- keys = get_key + get_secondary_indexes.values.flatten
203
- list = {}
204
- until keys.empty?
205
- convi = keys.shift(2)
206
- list[convi[0]] = convi[1]
207
- end
208
- list
209
- end
210
-
211
256
  def res2hash hash
212
257
  new_hash = {}
213
258
  return new_hash if hash.nil?
214
259
  hash
215
260
  end
216
261
 
217
-
262
+ # query
218
263
  def query_without_index value, option
219
264
  keys = {}
220
265
 
@@ -231,12 +276,12 @@ module Dynamosaurus
231
276
  def get_item_key value
232
277
  if value.is_a? Array
233
278
  {
234
- get_key[0] => value[0].to_s,
235
- get_key[2] => value[1].to_s,
279
+ hash_key => value[0].to_s,
280
+ range_key => value[1].to_s,
236
281
  }
237
282
  else
238
283
  {
239
- get_key[0] => value.to_s,
284
+ hash_key => value.to_s,
240
285
  }
241
286
  end
242
287
  end
@@ -308,6 +353,7 @@ module Dynamosaurus
308
353
  end
309
354
  end
310
355
  end
356
+ # end of query
311
357
 
312
358
  # public method
313
359
  def get value, option={}
@@ -334,27 +380,59 @@ module Dynamosaurus
334
380
  end
335
381
  end
336
382
 
337
- def batch_get_item keys
338
- return nil if keys.nil? or keys.empty?
339
- Dynamosaurus.logger << "batch_get_item #{table_name} #{keys}"
340
- if get_key.size == 2
341
- my_keys = keys.map{|_key| {get_key[0].to_s => _key.to_s } }
383
+ def get_orderd_key_from_hash hash
384
+ get_orderd_key( (hash[hash_key.to_sym] || hash[hash_key.to_s]),
385
+ (hash[range_key.to_sym] || hash[range_key.to_s]))
386
+ end
387
+
388
+ def get_orderd_key_from_array array
389
+ get_orderd_key(array[0], array[1])
390
+ end
391
+
392
+ def get_orderd_key value1, value2
393
+ {
394
+ hash_key.to_s => value1,
395
+ range_key.to_s => value2
396
+ }
397
+ end
398
+
399
+ def conv_key_array keys
400
+ unless has_renge
401
+ keys.map{|_key| {hash_key.to_s => _key.to_s } }
342
402
  else
343
- my_keys = []
344
- keys[get_key[0]].each do |key1|
345
- keys[get_key[2]].each do |key2|
346
- my_keys << {
347
- get_key[0].to_s => key1,
348
- get_key[2].to_s => key2,
349
- }
403
+ if keys.is_a?(Array)
404
+ if keys[0].is_a?(Array)
405
+ keys.map{|key| get_orderd_key_from_array(key)}
406
+ elsif keys[0].is_a?(Hash)
407
+ keys.map{|key| get_orderd_key_from_hash(key)}
408
+ else
409
+ [get_orderd_key_from_array(keys)]
410
+ end
411
+ else
412
+ _keys = []
413
+ ((p_key = keys[hash_key]).is_a?(Array) ? p_key : [p_key]).each do |key1|
414
+ if (r_key = keys[range_key]).is_a?(Array)
415
+ r_key.each do |key2|
416
+ _keys << get_orderd_key(key1, key2)
417
+ end
418
+ else
419
+ _keys << get_orderd_key(key1, r_key)
420
+ end
350
421
  end
422
+ _keys
351
423
  end
352
424
  end
425
+ end
426
+
427
+ def batch_get_item keys
428
+ return nil if keys.nil? or keys.empty?
429
+ Dynamosaurus.logger << "batch_get_item #{table_name} #{keys}"
430
+ _keys = conv_key_array(keys)
353
431
 
354
432
  res = dynamo_db.batch_get_item(
355
433
  :request_items => {
356
434
  table_name => {
357
- :keys => my_keys
435
+ :keys => _keys
358
436
  }
359
437
  })
360
438
 
@@ -392,7 +470,16 @@ module Dynamosaurus
392
470
  end
393
471
 
394
472
  def put hash, num_hash={}, return_values=nil
473
+ new_hash = put_data(hash, num_hash)
395
474
 
475
+ res = dynamo_db.put_item(
476
+ :table_name => table_name,
477
+ :item => new_hash,
478
+ :return_values => return_values || "NONE"
479
+ )
480
+ end
481
+
482
+ def put_data hash, num_hash={}
396
483
  new_hash = {}
397
484
  hash.each{|key, value|
398
485
  new_hash[key] = value unless value.nil?
@@ -400,22 +487,55 @@ module Dynamosaurus
400
487
  num_hash.merge({:updated_at => Time.now.to_i}).each{|key, value|
401
488
  new_hash[key] = value.to_i unless value.nil?
402
489
  } if num_hash
490
+ new_hash
491
+ end
403
492
 
404
- res = dynamo_db.put_item(
405
- :table_name => table_name,
406
- :item => new_hash,
407
- :return_values => return_values || "NONE"
493
+ def batch_write_item put_items = [], delete_items = []
494
+ return nil if (put_items.nil? or put_items.empty?) and (delete_items.nil? or delete_items.empty?)
495
+ Dynamosaurus.logger << "batch_write_item #{table_name}"
496
+
497
+ requests = []
498
+ if put_items and put_items.size > 0
499
+ put_items.each do |item|
500
+ if item["hash"] or item["num_hash"]
501
+ new_item = put_data(item["hash"], item["num_hash"])
502
+ else
503
+ new_item = item.merge({:updated_at => Time.now.to_i})
504
+ end
505
+ requests << {
506
+ put_request: {
507
+ item: new_item
508
+ }
509
+ }
510
+ end
511
+ end
512
+
513
+ if delete_items and delete_items.size > 0
514
+ conv_key_array(delete_items).map{|key|
515
+ requests << {
516
+ delete_request: {
517
+ key: key
518
+ }
519
+ }
520
+ }
521
+ end
522
+
523
+ res = dynamo_db.batch_write_item(
524
+ request_items: {
525
+ table_name => requests
526
+ },
527
+ return_consumed_capacity: "TOTAL"
408
528
  )
529
+ res
409
530
  end
410
531
 
411
532
  def save hash, num_hash={}, return_values=nil
412
533
  put(hash, num_hash, return_values)
413
- my_keys = get_key
414
534
 
415
- if my_keys.size == 4
416
- get([hash[my_keys[0]], hash[my_keys[2]]])
535
+ if has_renge
536
+ get([hash[hash_key], hash[range_key]])
417
537
  else
418
- get(hash[my_keys[0]])
538
+ get(hash[hash_key])
419
539
  end
420
540
  end
421
541
 
@@ -430,11 +550,10 @@ module Dynamosaurus
430
550
  }
431
551
  end
432
552
 
433
- class_key = get_key
434
553
  keys = {
435
- class_key[0].to_sym => key.is_a?(Array) ? key[0] : key
554
+ hash_key.to_sym => key.is_a?(Array) ? key[0] : key
436
555
  }
437
- keys[class_key[2].to_sym] = key[1] if class_key.size > 2
556
+ keys[range_key.to_sym] = key[1] if has_renge
438
557
 
439
558
  query ={
440
559
  :table_name => table_name,
@@ -1,3 +1,3 @@
1
1
  module Dynamosaurus
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dynamosaurus::DynamoBase do
4
+ before(:all) do
5
+ ENV['DYNAMODB_SUFFIX'] = "_local"
6
+
7
+ Aws.config = {
8
+ :endpoint => "http://localhost:8000",
9
+ :region => 'local_test',
10
+ }
11
+ Dynamosaurus::DynamoBase.create_tables
12
+ end
13
+
14
+ after(:all) do
15
+ connect = Dynamosaurus::DynamoBase.dynamo_db
16
+ Dynamosaurus::DynamoBase.tables.each do |table_name|
17
+ connect.delete_table(:table_name => table_name)
18
+ end
19
+ end
20
+
21
+ it 'simple ordered kvs test' do
22
+ expect(Dynamosaurus::DynamoBase.all_models).to match_array [Like, DynamoModelWithoutTableField, DynamoModelWithTableField, Comment, SimpleOrderedKVS, SimpleKVS]
23
+ expect(Dynamosaurus::DynamoBase.tables).to match_array ["comment_local", "dynamomodelwithouttablefield_local", "like_local", "simplekvs_local", "simpleorderedkvs_local", "table_name"]
24
+
25
+ expect(SimpleOrderedKVS.table_name).to match "simpleorderedkvs_local"
26
+ expect(SimpleOrderedKVS.get_key).to match_array [:simple_key, :s, :simple_id, :s]
27
+
28
+ expect(SimpleOrderedKVS.schema).to match_array [
29
+ [ :attribute_definitions, [
30
+ {:attribute_name=>"simple_key", :attribute_type=>"S"},
31
+ {:attribute_name=>"simple_id", :attribute_type=>"S"},
32
+ {:attribute_name=>"updated_at", :attribute_type=>"N"}
33
+ ]],
34
+ [ :key_schema, [
35
+ {:key_type=>"HASH", :attribute_name=>"simple_key"}, {:key_type=>"RANGE", :attribute_name=>"simple_id"}
36
+ ]],
37
+ [ :local_secondary_indexes, [
38
+ { :index_name=>:updated_at_index,
39
+ :key_schema=>[ {:key_type=>"HASH", :attribute_name=>:simple_key}, {:key_type=>"RANGE", :attribute_name=>:updated_at}],
40
+ :projection=>{:projection_type=>"KEYS_ONLY"}}
41
+ ]],
42
+ [:provisioned_throughput, {:read_capacity_units=>10, :write_capacity_units=>10}], [:table_name, "simpleorderedkvs_local"]
43
+ ]
44
+ expect(SimpleOrderedKVS.get_global_indexes).to match({})
45
+ expect(SimpleOrderedKVS.get_secondary_indexes).to match({:updated_at_index=>[:simple_key, :s, :updated_at, :n]})
46
+ expect(SimpleOrderedKVS.get_indexes).to match({:updated_at_index=>[:simple_key, :s, :updated_at, :n]})
47
+
48
+
49
+ expect(SimpleKVS.schema).to match_array [
50
+ [:attribute_definitions, [
51
+ {:attribute_name=>"simple_key", :attribute_type=>"S"}]
52
+ ],
53
+ [:key_schema, [
54
+ {:key_type=>"HASH", :attribute_name=>"simple_key"}
55
+ ]],
56
+ [:provisioned_throughput, {:read_capacity_units=>10, :write_capacity_units=>10}], [:table_name, "simplekvs_local"]
57
+ ]
58
+
59
+ expect(Comment.schema).to match_array [[:attribute_definitions, [{:attribute_name=>"content_id", :attribute_type=>"S"}, {:attribute_name=>"message_id", :attribute_type=>"S"}, {:attribute_name=>"user_id", :attribute_type=>"S"}]], [:global_secondary_indexes, [{:index_name=>:user_index, :key_schema=>[{:key_type=>"HASH", :attribute_name=>:user_id}], :projection=>{:projection_type=>"KEYS_ONLY"}, :provisioned_throughput=>{:read_capacity_units=>10, :write_capacity_units=>10}}]], [:key_schema, [{:key_type=>"HASH", :attribute_name=>"content_id"}, {:key_type=>"RANGE", :attribute_name=>"message_id"}]], [:provisioned_throughput, {:read_capacity_units=>10, :write_capacity_units=>10}], [:table_name, "comment_local"]]
60
+
61
+ end
62
+ end
@@ -55,12 +55,22 @@ describe Dynamosaurus do
55
55
 
56
56
 
57
57
  batch_items = SimpleOrderedKVS.batch_get_item({:simple_key => ["key"], :simple_id => ["1", "2", "3"]})
58
- expect(orderd_items.size).to eq 3
58
+ expect(batch_items.size).to eq 3
59
59
 
60
60
  kvs = SimpleOrderedKVS.first
61
61
  kvs2 = SimpleOrderedKVS.get({:simple_key => kvs.simple_key, :updated_at => kvs.updated_at})
62
62
  expect(kvs.simple_id).to eq kvs2[0].simple_id
63
63
 
64
+ put_items = [{simple_key: "key", simple_id: "a"}, {simple_key: "key", simple_id: "b"}]
65
+ delete_keys = {simple_key: ["key"], simple_id: ["1", "2"]}
66
+ batch_put_items = SimpleOrderedKVS.batch_write_item(put_items, delete_keys)
67
+
68
+ batch_items = SimpleOrderedKVS.batch_get_item({:simple_key => ["key"], :simple_id => ["a", "b", "c"]})
69
+ expect(batch_items.size).to eq 2
70
+
71
+ batch_items = SimpleOrderedKVS.batch_get_item({:simple_key => ["key"], :simple_id => ["1", "2", "3"]})
72
+ expect(batch_items.size).to eq 1
73
+
64
74
  end
65
75
 
66
76
  it 'simple kvs test' do
@@ -102,6 +112,7 @@ describe Dynamosaurus do
102
112
  kvs.num = 100
103
113
  kvs.save
104
114
 
115
+
105
116
  kvs = SimpleKVS.first
106
117
  expect(kvs.num).to eq 100
107
118
 
@@ -124,6 +135,45 @@ describe Dynamosaurus do
124
135
  kvs = SimpleKVS.get("key3")
125
136
  expect(kvs).to be_nil
126
137
 
138
+ res = SimpleKVS.save({:simple_key => "key4"}, {:num => 3})
139
+ expect(res.simple_key).to eq "key4"
140
+ expect(res.num).to eq 3
141
+ end
142
+
143
+ it 'internel method test' do
144
+ conv_keys = SimpleOrderedKVS.conv_key_array({:simple_key => ["key1", "key2"], :simple_id => ["1", "2", "3"]})
145
+ expect(conv_keys).to eq [
146
+ {"simple_key"=>"key1", "simple_id"=>"1"}, {"simple_key"=>"key1", "simple_id"=>"2"}, {"simple_key"=>"key1", "simple_id"=>"3"},
147
+ {"simple_key"=>"key2", "simple_id"=>"1"}, {"simple_key"=>"key2", "simple_id"=>"2"}, {"simple_key"=>"key2", "simple_id"=>"3"}
148
+ ]
149
+
150
+ conv_keys = SimpleOrderedKVS.conv_key_array({:simple_key => "key", :simple_id => ["1", "2", "3"]})
151
+ expect(conv_keys).to eq [
152
+ {"simple_key"=>"key", "simple_id"=>"1"}, {"simple_key"=>"key", "simple_id"=>"2"}, {"simple_key"=>"key", "simple_id"=>"3"}
153
+ ]
154
+
155
+ conv_keys = SimpleOrderedKVS.conv_key_array({:simple_key => ["key1","key2"], :simple_id => "1"})
156
+ expect(conv_keys).to eq [
157
+ {"simple_key"=>"key1", "simple_id"=>"1"}, {"simple_key"=>"key2", "simple_id"=>"1"}
158
+ ]
159
+
160
+ conv_keys = SimpleOrderedKVS.conv_key_array({:simple_key => "key1", :simple_id => "1"})
161
+ expect(conv_keys).to eq [
162
+ {"simple_key"=>"key1", "simple_id"=>"1"}
163
+ ]
164
+
165
+ conv_keys = SimpleOrderedKVS.conv_key_array([{:simple_key => "key1", :simple_id => "1"}, {:simple_key => "key1", :simple_id => "2"}])
166
+ expect(conv_keys).to eq [
167
+ {"simple_key"=>"key1", "simple_id"=>"1"}, {"simple_key"=>"key1", "simple_id"=>"2"}
168
+ ]
169
+ conv_keys = SimpleOrderedKVS.conv_key_array(["key1", "1"])
170
+ expect(conv_keys).to eq [
171
+ {"simple_key"=>"key1", "simple_id"=>"1"}
172
+ ]
173
+ conv_keys = SimpleOrderedKVS.conv_key_array([["key1", "1"], ["key1", "2"]])
174
+ expect(conv_keys).to eq [
175
+ {"simple_key"=>"key1", "simple_id"=>"1"}, {"simple_key"=>"key1", "simple_id"=>"2"}
176
+ ]
127
177
  end
128
178
 
129
179
  shared_examples_for 'Basic CRUD' do
@@ -161,11 +211,6 @@ describe Dynamosaurus do
161
211
 
162
212
  describe 'table options' do
163
213
  context 'when table-name is given' do
164
- class DynamoModelWithTableField < Dynamosaurus::DynamoBase
165
- table name: 'table_name'
166
- key :content_id, :string, :message_id, :string
167
- end
168
-
169
214
  it_should_behave_like 'Basic CRUD' do
170
215
  let!(:model_name) { 'DynamoModelWithTableField' }
171
216
  end
@@ -174,10 +219,6 @@ describe Dynamosaurus do
174
219
  end
175
220
 
176
221
  context 'when table-name is not given' do
177
- class DynamoModelWithoutTableField < Dynamosaurus::DynamoBase
178
- key :content_id, :string, :message_id, :string
179
- end
180
-
181
222
  it_should_behave_like 'Basic CRUD' do
182
223
  let!(:model_name) { 'DynamoModelWithoutTableField' }
183
224
  end
@@ -13,3 +13,17 @@ class Comment < Dynamosaurus::DynamoBase
13
13
  key :content_id, :string, :message_id, :string
14
14
  global_index :user_index, :user_id, :string
15
15
  end
16
+
17
+ class DynamoModelWithTableField < Dynamosaurus::DynamoBase
18
+ table name: 'table_name'
19
+ key :content_id, :string, :message_id, :string
20
+ end
21
+
22
+ class DynamoModelWithoutTableField < Dynamosaurus::DynamoBase
23
+ key :content_id, :string, :message_id, :string
24
+ end
25
+
26
+ class Like < Dynamosaurus::DynamoBase
27
+ key :object_id, :string, :user_id, :string
28
+ global_index :user_index, :user_id, :string
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamosaurus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isamu Arimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - lib/dynamosaurus/dynamo_class.rb
88
88
  - lib/dynamosaurus/logger.rb
89
89
  - lib/dynamosaurus/version.rb
90
+ - spec/dynamo_class_spec.rb
90
91
  - spec/dynamosaurus_spec.rb
91
92
  - spec/spec_helper.rb
92
93
  - spec/testmodel.rb
@@ -115,6 +116,7 @@ signing_key:
115
116
  specification_version: 4
116
117
  summary: Dynamodb simple ORM
117
118
  test_files:
119
+ - spec/dynamo_class_spec.rb
118
120
  - spec/dynamosaurus_spec.rb
119
121
  - spec/spec_helper.rb
120
122
  - spec/testmodel.rb