dymos 0.0.4 → 0.0.5

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: 0f19efc160366df30ebdf4cf8bddf10b96d7bc52
4
- data.tar.gz: fe07218445f99d87f4e43eba77e01fa75d8a18e0
3
+ metadata.gz: 036d8dac33aac8670a6e98ebc1b5edd52acb193f
4
+ data.tar.gz: bbcc269f35f7a4a717a62937e07281efd24e0f03
5
5
  SHA512:
6
- metadata.gz: 587a325be4f0e04bea0987a232cf3e8a82763db102c02cb3fc54e434284533e45967237af8f18360ac3b2ab21da005df4675190d830f06bec05bdc166a833fa2
7
- data.tar.gz: 2435827548726a4c26a45e3743dc214e193f0a61746260ea8ec88284b1abdec30be0573a07188117d3d303b81a6beb9bc576bc93e84e25ab375c008fd7e6d0e9
6
+ metadata.gz: 6e60e93b0a7b52e8758d2e62e5c3a3d2c2a810edee67fa0986257651158e2b4e61dffd3617ab65da12709fdc964d534274082cffc9744a8fdfaf7c3affaf57f3
7
+ data.tar.gz: ac6f103586f8d7d60f28670032e6c4bed0f0fd365dd950f4e739548865fccdaf2c5e7d8b93589283b20a9f45ddaf4e81a4d5d98d7c7399ca790217efe4eb5c6f
data/lib/dymos/model.rb CHANGED
@@ -5,6 +5,7 @@ module Dymos
5
5
  class Model
6
6
  include ActiveModel::Model
7
7
  extend Dymos::Command
8
+ attr_accessor :metadata
8
9
 
9
10
  def initialize(params={})
10
11
  @attributes = {}
@@ -22,7 +22,7 @@ module Dymos
22
22
 
23
23
  end
24
24
 
25
- def execute(client = nil)
25
+ def raw_execute(client=nil)
26
26
  client ||= Aws::DynamoDB::Client.new
27
27
  begin
28
28
  before_send_query command, query
@@ -31,32 +31,50 @@ module Dymos
31
31
  rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
32
32
  return false
33
33
  end
34
+ res
35
+ end
36
+
37
+ def execute(client = nil)
38
+ res = raw_execute client
39
+
40
+ return false unless res
41
+
34
42
  if @class_name.present?
35
- if res.data.respond_to? :items
43
+ if res.data.respond_to? :items # scan, query
44
+ metadata = extract(res, :items)
36
45
  res.data[:items].map do |datum|
37
46
  obj = Object.const_get(@class_name).new
38
47
  obj.attributes = datum
48
+ obj.metadata = metadata
39
49
  obj
40
50
  end
41
- elsif res.data.respond_to? :attributes
51
+ elsif res.data.respond_to? :attributes # put_item, update_item
42
52
  return nil if res.attributes.nil?
43
53
  obj = Object.const_get(@class_name).new
44
54
  obj.attributes = res.attributes
55
+ obj.metadata = extract(res, :attributes)
45
56
  obj
46
57
  elsif res.respond_to? :data
47
- if res.data.respond_to? :item
58
+ if res.data.respond_to? :item # get_item
48
59
  obj = Object.const_get(@class_name).new
49
60
  obj.attributes = res.data.item
61
+ obj.metadata = extract(res, :item)
50
62
  obj
51
63
  else
52
- res.data.to_hash
64
+ res.data.to_hash # describe
53
65
  end
54
66
  end
55
67
  else
56
- res.data
68
+ res.data.to_hash #list_tables
57
69
  end
58
70
 
59
71
  end
72
+
73
+ def extract(res, ignoreKey)
74
+ keys = res.data.members.reject { |a| a == ignoreKey }
75
+ array=keys.map { |k| [k, res.data[k]] }
76
+ array.reduce({}) { |hash, value| hash.merge({value[0] => value[1]}) }
77
+ end
60
78
  end
61
79
  end
62
80
  end
data/lib/dymos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dymos
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -14,52 +14,10 @@ describe Dymos::Query::Builder do
14
14
  end
15
15
 
16
16
  it "execute" do
17
- client = Aws::DynamoDB::Client.new
18
- expect(query.execute(client).methods.include? :table_names).to eq(true)
17
+ result = query.execute
18
+ expect(result.include? :table_names).to eq(true)
19
19
  end
20
20
  end
21
21
 
22
- describe :put_item do
23
- before :all do
24
- client = Aws::DynamoDB::Client.new
25
- # client.delete_table(table_name: 'test_put_item') if client.list_tables[:table_names].include?('test_put_item')
26
- # client.create_table(
27
- # table_name: 'test_put_item',
28
- # attribute_definitions: [
29
- # {attribute_name: 'id', attribute_type: 'S'}
30
- # ],
31
- # key_schema: [
32
- # {attribute_name: 'id', key_type: 'HASH'}
33
- # ],
34
- # provisioned_throughput: {
35
- # read_capacity_units: 1,
36
- # write_capacity_units: 1,
37
- # })
38
- # client.put_item(table_name: 'test_put_item', item: {id: 'hoge', name: '太郎'})
39
- # client.put_item(table_name: 'test_put_item', item: {id: 'fuga', name: '次郎'})
40
- # client.put_item(table_name: 'test_put_item', item: {id: 'piyo', name: '三郎'})
41
- end
42
- let(:client) { Aws::DynamoDB::Client.new }
43
- let(:query) { Dymos::Query::Builder.new(:put_item, "test_put_item") }
44
-
45
- it 'put' do
46
- # User.put.item(id:"hoge",name:"太郎").expected(id:'hoge')
47
- # query.query = {
48
- # table_name: query.table_name,
49
- # item: {
50
- # id: "hoge",
51
- # name: "太郎2",
52
- # },
53
- # expected: {
54
- # id: Dymos::Query::Expect.new(:s).condition(:==, 'hoge').data,
55
- # name: Dymos::Query::Expect.new(:s).condition(:==, '太郎2').data,
56
- # },
57
- # return_values: "ALL_OLD",
58
- # }
59
- # result = query.execute client
60
- # expect(result).to eq('hoge')
61
- end
62
-
63
- end
64
22
  end
65
23
 
@@ -38,7 +38,8 @@ describe Dymos::Query::Describe do
38
38
  end
39
39
 
40
40
  it :execute do
41
- expect(TestItem.describe.execute[:table][:attribute_definitions]).to eq([{:attribute_name => "id", :attribute_type => "S"}, {:attribute_name => "category_id", :attribute_type => "N"}])
41
+ result=TestItem.describe.execute
42
+ expect(result[:table][:attribute_definitions]).to eq([{:attribute_name => "id", :attribute_type => "S"}, {:attribute_name => "category_id", :attribute_type => "N"}])
42
43
  end
43
44
 
44
45
  end
@@ -43,7 +43,7 @@ describe Dymos::Query::GetItem do
43
43
  # p client.scan(table_name: "test_get_item")
44
44
  res = query.execute client
45
45
  expect(res.id).to eq('hoge')
46
-
46
+ expect(res.metadata).to eq(consumed_capacity: nil)
47
47
 
48
48
  # expect(res).to eq({})
49
49
  # p client.scan(table_name:"test_get_item")
@@ -73,15 +73,16 @@ describe Dymos::Query::PutItem do
73
73
  # })
74
74
  # end
75
75
 
76
- # it "条件ありput_item実行 成功すると古いデータを返す" do
77
- # query = TestPutItem.put.item(id: "hoge", name: "次郎").expected(name: "== 太郎")
78
- # result = query.execute client
79
- # expect(result.attributes).to eq({id: "hoge", name: "太郎"})
80
- # end
76
+ it "条件ありput_item実行 成功すると古いデータを返す" do
77
+ query = TestItem.put.item(id: "hoge", name: "次郎").expected(name: "== 太郎")
78
+ result = query.execute client
79
+ expect(result.attributes).to eq({id: "hoge", name: "太郎"})
80
+ expect(result.metadata).to eq(consumed_capacity: nil, item_collection_metrics: nil)
81
+ end
81
82
 
82
83
  describe "条件指定" do
83
84
  it "undefined operator" do
84
- expect{TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "= 1")}.to raise_error(ArgumentError)
85
+ expect { TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "= 1") }.to raise_error(ArgumentError)
85
86
  end
86
87
 
87
88
  describe :== do
@@ -95,6 +96,7 @@ describe Dymos::Query::PutItem do
95
96
  it :execute do
96
97
  result = query.execute client
97
98
  expect(result.attributes).to eq({id: "fuga", category_id: 1})
99
+ expect(result.metadata).to eq(consumed_capacity: nil, item_collection_metrics: nil)
98
100
  end
99
101
  it :error do
100
102
  query = TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "== 2")
@@ -80,6 +80,7 @@ describe Dymos::Query::Query do
80
80
  it :execute do
81
81
  res = query.execute client
82
82
  expect(res.size).to eq(3)
83
+ expect(res.first.metadata).to eq(count: 3, scanned_count: 3, last_evaluated_key: nil, consumed_capacity: nil)
83
84
  end
84
85
 
85
86
 
@@ -41,7 +41,9 @@ describe Dymos::Query::Scan do
41
41
  end
42
42
 
43
43
  it :execute do
44
- expect(TestItem.scan.execute.size).to eq(5)
44
+ res=TestItem.scan.execute
45
+ expect(res.size).to eq(5)
46
+ expect(res.first.metadata).to eq(count: 5, scanned_count: 5, last_evaluated_key: nil, consumed_capacity: nil)
45
47
  end
46
48
 
47
49
  end
@@ -109,6 +109,7 @@ describe Dymos::Query::UpdateItem do
109
109
  it "成功すると新しいアイテムを返す" do
110
110
  res = query.execute client
111
111
  expect(res.name).to eq("百合子")
112
+ expect(res.metadata[:consumed_capacity]).to eq(nil)
112
113
  end
113
114
  end
114
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dymos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - hoshina85
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler