alephant-lookup 0.2.0 → 0.3.0

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: 2dd351965cd12a44c7c28fa7d1ff14a0b63ea3ee
4
- data.tar.gz: 6699863b7fc4d97b4dfd4cc987c832d86aa455cf
3
+ metadata.gz: 40a0521ddd1f119f7882e1dec17836b34746aebb
4
+ data.tar.gz: ff07efca80bd0b60ba24869e844cb40a8f399bb1
5
5
  SHA512:
6
- metadata.gz: de5dfae1a098baebd2a25cbc418e4e8b696339a172acb95536c4ad9afd83addc4b574b284ffcc9e6ec9c31eff2887f5fcf924a1778c506f28dc85e32878800c4
7
- data.tar.gz: 3dea58769882c33d0159b6a6a64b61708e99780ff62ca5273608244b70cfb09843846ad8ad1bf7a3adf4ae59adee87c3c8e8217e4cb445e2b621b7230f343013
6
+ metadata.gz: b72048abff1b1a2a06a1da8eb3108baf6e9a98355e38a8dc34628c32e99284bfbf804b40598395ac219f04f0729ecbfbd337ce1bde883bc6a47f50594c5a44ea
7
+ data.tar.gz: 9aea0f80fa152b25a927f78cfcf5c88e82a2ce367cd81c4684c31d146b3b127a13b0837ef8a3dd060ad6ca9d85212b7969c9d8c37aa30496054a506b19d9b56c
@@ -16,7 +16,6 @@ module Alephant
16
16
  logger.info "LookupHelper#initialize(#{lookup_table.table_name})"
17
17
 
18
18
  @lookup_table = lookup_table
19
- @lookup_table.create
20
19
  end
21
20
 
22
21
  def read(id, opts, batch_version)
@@ -29,13 +28,11 @@ module Alephant
29
28
  logger.info "LookupHelper#write(#{id}, #{opts}, #{batch_version}, #{location})"
30
29
 
31
30
  LookupLocation.new(id, opts, batch_version, location).tap do |l|
32
- lookup_table.table.batch_put([
33
- {
34
- :component_key => l.component_key,
35
- :batch_version => l.batch_version,
36
- :location => l.location
37
- }
38
- ])
31
+ lookup_table.write(
32
+ l.component_key,
33
+ l.batch_version,
34
+ l.location
35
+ )
39
36
  end
40
37
  end
41
38
 
@@ -7,65 +7,31 @@ require "alephant/support/dynamodb/table"
7
7
  module Alephant
8
8
  module Lookup
9
9
  class LookupTable < ::Alephant::Support::DynamoDB::Table
10
- attr_reader :table_name
10
+ attr_reader :table_name, :client
11
11
 
12
- SCHEMA = {
13
- :hash_key => {
14
- :component_key => :string
15
- },
16
- :range_key => {
17
- :batch_version => :number
18
- }
19
- }
20
-
21
- def initialize(table_name, config = DEFAULT_CONFIG)
12
+ def initialize(table_name)
22
13
  @mutex = Mutex.new
23
- @dynamo_db = AWS::DynamoDB.new
14
+ @client = AWS::DynamoDB::Client::V20120810.new
24
15
  @table_name = table_name
25
- @config = config
26
- end
27
-
28
- def create
29
- @mutex.synchronize do
30
- ensure_table_exists
31
- ensure_table_active
32
- end
33
16
  end
34
17
 
35
- def table
36
- @table ||= @dynamo_db.tables[@table_name]
18
+ def write(component_key, version, location)
19
+ client.put_item({
20
+ :table_name => table_name,
21
+ :item => {
22
+ 'component_key' => {
23
+ 'S' => component_key.to_s
24
+ },
25
+ 'batch_version' => {
26
+ 'N' => version.to_s
27
+ },
28
+ 'location' => {
29
+ 'S' => location.to_s
30
+ }
31
+ }
32
+ })
37
33
  end
38
34
 
39
- private
40
-
41
- def ensure_table_exists
42
- create_dynamodb_table unless table.exists?
43
- end
44
-
45
- def ensure_table_active
46
- sleep_until_table_active unless table_active?
47
- end
48
-
49
- def create_dynamodb_table
50
- @table = @dynamo_db.tables.create(
51
- @table_name,
52
- @config[:read_units],
53
- @config[:write_units],
54
- SCHEMA
55
- )
56
- end
57
-
58
- def table_active?
59
- table.status == :active
60
- end
61
-
62
- def sleep_until_table_active
63
- begin
64
- Timeout::timeout(TIMEOUT) do
65
- sleep 1 until table_active?
66
- end
67
- end
68
- end
69
35
  end
70
36
  end
71
37
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Lookup
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -18,7 +18,6 @@ describe Alephant::Lookup do
18
18
  it "calls create on lookup_table" do
19
19
  table = double()
20
20
  table.should_receive(:table_name)
21
- table.should_receive(:create)
22
21
  subject.new(table, Logger.new(STDOUT))
23
22
  end
24
23
  end
@@ -73,26 +72,25 @@ describe Alephant::Lookup do
73
72
 
74
73
  describe "#write(opts, location)" do
75
74
  it "does not fail" do
76
- AWS::DynamoDB
75
+
76
+ AWS::DynamoDB::Client::V20120810
77
77
  .any_instance
78
78
  .stub(:initialize)
79
79
  .and_return(
80
80
  double().as_null_object
81
81
  )
82
82
 
83
- ddb_table = double().as_null_object
84
- ddb_table
85
- .should_receive(:batch_put)
86
- .with([{
87
- :component_key => "id/7e0c33c476b1089500d5f172102ec03e",
88
- :batch_version => "0",
89
- :location => "/location"
90
- }])
91
-
92
83
  lookup_table = double().as_null_object
93
84
  lookup_table
94
- .should_receive(:table)
95
- .and_return(ddb_table)
85
+ .should_receive(:table_name)
86
+ .and_return('test')
87
+ lookup_table
88
+ .should_receive(:write)
89
+ .with(
90
+ "id/7e0c33c476b1089500d5f172102ec03e",
91
+ "0",
92
+ "/location"
93
+ )
96
94
 
97
95
  Alephant::Lookup::LookupHelper
98
96
  .any_instance
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Kenny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -244,4 +244,3 @@ summary: Lookup a location in S3 using DynamoDB.
244
244
  test_files:
245
245
  - spec/lookup_spec.rb
246
246
  - spec/spec_helper.rb
247
- has_rdoc: