alephant-lookup 0.1.6 → 0.1.7
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 +4 -4
- data/README.md +54 -8
- data/alephant-lookup.gemspec +1 -0
- data/lib/alephant/lookup/lookup_helper.rb +6 -2
- data/lib/alephant/lookup/lookup_location.rb +1 -1
- data/lib/alephant/lookup/lookup_query.rb +11 -11
- data/lib/alephant/lookup/lookup_table.rb +6 -9
- data/lib/alephant/lookup/version.rb +1 -1
- data/spec/lookup_spec.rb +25 -14
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3721f4977e35f2aa609dd85c2c9debfae8fd7dac
|
4
|
+
data.tar.gz: cc50c1eee20d3a282b2c5bde7c46eb5744942b30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60bc1d72053a8970d0542e46d322fd9fc2535bc492fa052ad0217a68feda5477f6a7e0d86b868fc69bfa3366d396238091b2ad424cd8474834543ba7dd76c3f6
|
7
|
+
data.tar.gz: de5efa73bebc058ebbb21d8c28f81fbe745c9308fc40840ae10d90e776372a0cdb4352c1ad96ef6bddc348b014f4a52f5b628d393a060ff91dfe6ece65eeaede
|
data/README.md
CHANGED
@@ -25,22 +25,68 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```rb
|
28
|
-
require
|
28
|
+
require "alephant/lookup"
|
29
|
+
# => true
|
29
30
|
|
30
|
-
|
31
|
+
AWS.config.region
|
32
|
+
# => "us-east-1"
|
31
33
|
|
32
|
-
|
34
|
+
AWS.config(:region => 'eu-west-1')
|
35
|
+
# => <AWS::Core::Configuration>
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
AWS.config.region
|
38
|
+
# => "eu-west-1"
|
36
39
|
|
37
|
-
lookup.
|
38
|
-
# =>
|
40
|
+
lookup = Alephant::Lookup.create("mark_lookup_test")
|
41
|
+
# => #<Alephant::Lookup::LookupHelper:0x1f881554
|
42
|
+
# @lookup_table=
|
43
|
+
# #<Alephant::Lookup::LookupTable:0x7f8dd355
|
44
|
+
# @config={:write_units=>5, :read_units=>10},
|
45
|
+
# @dynamo_db=<AWS::DynamoDB>,
|
46
|
+
# @mutex=#<Mutex:0x6a3f8a94>,
|
47
|
+
# @range_found=false,
|
48
|
+
# @table=<AWS::DynamoDB::Table table_name:mark_lookup_test>,
|
49
|
+
# @table_name="mark_lookup_test">>
|
50
|
+
|
51
|
+
dynamo_db = AWS::DynamoDB.new
|
52
|
+
# => <AWS::DynamoDB>
|
53
|
+
|
54
|
+
dynamo_db.tables["mark_lookup_test"].exists?
|
55
|
+
# => true
|
56
|
+
|
57
|
+
table = dynamo_db.tables["mark_lookup_test"]
|
58
|
+
# => <AWS::DynamoDB::Table table_name:mark_lookup_test>
|
59
|
+
|
60
|
+
table.status
|
61
|
+
# => :active
|
62
|
+
|
63
|
+
table.items.count
|
64
|
+
# => 0
|
65
|
+
|
66
|
+
table.items
|
67
|
+
# => <AWS::DynamoDB::ItemCollection>
|
68
|
+
|
69
|
+
table.items.put({ :component_key => "a/b", :batch_version => 1, :location => "a/c/b/1" })
|
70
|
+
# => <AWS::DynamoDB::Item table_name:mark_lookup_test hash_value:a/b range_value:0.1E1>
|
71
|
+
|
72
|
+
table.items.put({ :component_key => "d/e", :batch_version => 1, :location => "d/f/e/1" })
|
73
|
+
# => <AWS::DynamoDB::Item table_name:mark_lookup_test hash_value:d/e range_value:0.1E1>
|
74
|
+
|
75
|
+
lookup.truncate!
|
76
|
+
# => nil
|
77
|
+
|
78
|
+
component_id = "foo"
|
79
|
+
opts = { :key => :value }
|
80
|
+
batch_version = 1
|
81
|
+
location = "s3-bucket/location"
|
82
|
+
|
83
|
+
lookup.write(id, opts, batch_version, location)
|
84
|
+
lookup.read(id, opts, batch_version)
|
39
85
|
```
|
40
86
|
|
41
87
|
## Contributing
|
42
88
|
|
43
|
-
1. Fork it ( http://github.com
|
89
|
+
1. Fork it ( http://github.com/BBC-News/alephant-lookup/fork )
|
44
90
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
91
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
92
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/alephant-lookup.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "alephant/lookup/lookup_table"
|
2
|
+
require "alephant/lookup/lookup_query"
|
3
3
|
|
4
4
|
module Alephant
|
5
5
|
module Lookup
|
@@ -26,6 +26,10 @@ module Alephant
|
|
26
26
|
])
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def truncate!
|
31
|
+
@lookup_table.truncate!
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "crimp"
|
2
|
+
require "alephant/lookup/lookup_location"
|
3
3
|
|
4
4
|
module Alephant
|
5
5
|
module Lookup
|
@@ -23,26 +23,26 @@ module Alephant
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def s3_location_from(result)
|
26
|
-
result[:count] == 1 ? result[:member].first[
|
26
|
+
result[:count] == 1 ? result[:member].first["location"][:s] : nil
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_q
|
30
30
|
{
|
31
31
|
:table_name => table_name,
|
32
32
|
:consistent_read => true,
|
33
|
-
:select =>
|
34
|
-
:attributes_to_get => [
|
33
|
+
:select => "SPECIFIC_ATTRIBUTES",
|
34
|
+
:attributes_to_get => ["location"],
|
35
35
|
:key_conditions => {
|
36
|
-
|
37
|
-
:comparison_operator =>
|
36
|
+
"component_key" => {
|
37
|
+
:comparison_operator => "EQ",
|
38
38
|
:attribute_value_list => [
|
39
|
-
{
|
39
|
+
{ "s" => @lookup_location.component_key }
|
40
40
|
],
|
41
41
|
},
|
42
|
-
|
43
|
-
:comparison_operator =>
|
42
|
+
"batch_version" => {
|
43
|
+
:comparison_operator => "EQ",
|
44
44
|
:attribute_value_list => [
|
45
|
-
{
|
45
|
+
{ "n" => @lookup_location.batch_version.to_s }
|
46
46
|
]
|
47
47
|
}
|
48
48
|
}
|
@@ -1,17 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "aws-sdk"
|
2
|
+
require "thread"
|
3
|
+
require "timeout"
|
4
|
+
|
5
|
+
require "alephant/support/dynamodb/table"
|
4
6
|
|
5
7
|
module Alephant
|
6
8
|
module Lookup
|
7
|
-
class LookupTable
|
9
|
+
class LookupTable < ::Alephant::Support::DynamoDB::Table
|
8
10
|
attr_reader :table_name
|
9
11
|
|
10
|
-
TIMEOUT = 120
|
11
|
-
DEFAULT_CONFIG = {
|
12
|
-
:write_units => 5,
|
13
|
-
:read_units => 10
|
14
|
-
}
|
15
12
|
SCHEMA = {
|
16
13
|
:hash_key => {
|
17
14
|
:component_key => :string
|
data/spec/lookup_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Alephant::Lookup do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe ".create(table_name, component_id)" do
|
5
|
+
it "returns a lookup" do
|
6
6
|
Alephant::Lookup::LookupHelper
|
7
7
|
.any_instance
|
8
8
|
.stub(:initialize)
|
@@ -14,15 +14,15 @@ describe Alephant::Lookup do
|
|
14
14
|
describe Alephant::Lookup::LookupHelper do
|
15
15
|
subject { Alephant::Lookup::LookupHelper }
|
16
16
|
|
17
|
-
describe
|
18
|
-
it
|
17
|
+
describe "#initialize(table_name)" do
|
18
|
+
it "calls create on lookup_table" do
|
19
19
|
table = double()
|
20
20
|
table.should_receive(:create)
|
21
21
|
subject.new(table)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
25
|
+
describe "#read(id, opts, batch_version)" do
|
26
26
|
let(:expected_query) do
|
27
27
|
{
|
28
28
|
:table_name=>"table_name",
|
@@ -42,7 +42,7 @@ describe Alephant::Lookup do
|
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "queries DynamoDb and returns a location" do
|
46
46
|
AWS::DynamoDB::Client::V20120810
|
47
47
|
.any_instance
|
48
48
|
.stub(:initialize)
|
@@ -55,23 +55,23 @@ describe Alephant::Lookup do
|
|
55
55
|
{
|
56
56
|
:count => 1,
|
57
57
|
:member => [
|
58
|
-
{
|
58
|
+
{ "location" => { :s => "/location" } }
|
59
59
|
]
|
60
60
|
}
|
61
61
|
)
|
62
62
|
|
63
63
|
table = double().as_null_object
|
64
|
-
table.stub(:table_name).and_return(
|
64
|
+
table.stub(:table_name).and_return("table_name")
|
65
65
|
|
66
66
|
instance = subject.new(table)
|
67
|
-
lookup = instance.read(
|
67
|
+
lookup = instance.read("id", 0, {:variant => "foo"})
|
68
68
|
|
69
|
-
expect(lookup.location).to eq(
|
69
|
+
expect(lookup.location).to eq("/location")
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe
|
74
|
-
it
|
73
|
+
describe "#write(opts, location)" do
|
74
|
+
it "does not fail" do
|
75
75
|
AWS::DynamoDB
|
76
76
|
.any_instance
|
77
77
|
.stub(:initialize)
|
@@ -99,7 +99,18 @@ describe Alephant::Lookup do
|
|
99
99
|
.and_return(lookup_table)
|
100
100
|
|
101
101
|
instance = subject.new(lookup_table)
|
102
|
-
instance.write(
|
102
|
+
instance.write("id",{},"0","/location")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#truncate!" do
|
107
|
+
it "deletes all table rows" do
|
108
|
+
table = double()
|
109
|
+
table.stub(:create)
|
110
|
+
table.should_receive(:truncate!)
|
111
|
+
|
112
|
+
subject = Alephant::Lookup::LookupHelper.new(table)
|
113
|
+
subject.truncate!
|
103
114
|
end
|
104
115
|
end
|
105
116
|
end
|
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.1.
|
4
|
+
version: 0.1.7
|
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-
|
11
|
+
date: 2014-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
prerelease: false
|
166
166
|
type: :runtime
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: alephant-support
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirement: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
prerelease: false
|
180
|
+
type: :runtime
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: crimp
|
169
183
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -229,3 +243,4 @@ summary: Lookup a location in S3 using DynamoDB.
|
|
229
243
|
test_files:
|
230
244
|
- spec/lookup_spec.rb
|
231
245
|
- spec/spec_helper.rb
|
246
|
+
has_rdoc:
|