kvom 6.8.0.beta.200.809.bdfa8c3 → 6.8.0.beta.200.856.8c0fec5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -3
- data/kvom.gemspec +6 -6
- data/lib/kvom.rb +2 -1
- data/lib/kvom/adapter.rb +4 -4
- data/lib/kvom/adapter/base.rb +5 -0
- data/lib/kvom/adapter/couchdb_adapter.rb +18 -16
- data/lib/kvom/adapter/couchdb_document.rb +6 -2
- data/lib/kvom/adapter/dynamodb_adapter.rb +6 -2
- data/lib/kvom/adapter/dynamodb_document.rb +27 -51
- data/lib/kvom/adapter/filesystem_adapter.rb +130 -0
- data/lib/kvom/adapter/filesystem_document.rb +11 -0
- data/lib/kvom/adapter/key_attributes_document.rb +26 -0
- data/lib/kvom/base.rb +3 -0
- data/lib/kvom/document.rb +7 -1
- data/lib/kvom/lib.rb +5 -0
- data/lib/kvom/lib/json.rb +14 -0
- data/lib/kvom/lib/json_value.rb +39 -0
- data/lib/kvom/model_identity.rb +2 -0
- data/lib/kvom/not_found.rb +2 -0
- data/lib/kvom/storage.rb +4 -4
- data/lib/kvom/storage/base.rb +50 -72
- data/lib/kvom/storage/cache_with_prefix.rb +7 -1
- data/lib/kvom/storage/file_system_storage.rb +18 -17
- data/lib/kvom/storage/not_found.rb +3 -6
- data/lib/kvom/storage/s3_storage.rb +55 -53
- data/spec/adaptor/base_spec.rb +87 -0
- data/spec/lib/json_spec.rb +30 -0
- data/spec/spec_helper.rb +15 -3
- data/tmp/.gitignore +3 -0
- metadata +47 -52
data/spec/adaptor/base_spec.rb
CHANGED
@@ -109,6 +109,93 @@ describe Kvom::Base do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
describe "adapter.query(<hash_value>, <range_spec>)" do
|
113
|
+
|
114
|
+
def random_id(id)
|
115
|
+
$base_spec_random_id ||= SecureRandom.hex(8)
|
116
|
+
"#{$base_spec_random_id}#{id}"
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_of_keys(documents)
|
120
|
+
keys = documents.map{|doc| doc.key}.to_set
|
121
|
+
keys.size.should == documents.size
|
122
|
+
keys
|
123
|
+
end
|
124
|
+
|
125
|
+
def create_document(id)
|
126
|
+
document = adapter.new_document(random_id(id), {})
|
127
|
+
adapter.save(document)
|
128
|
+
document
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:adapter) {TestModel.adapter}
|
132
|
+
|
133
|
+
let(:one_001) {create_document("one|001")}
|
134
|
+
let(:one_002) {create_document("one|002")}
|
135
|
+
let(:one_0021) {create_document("one|0021")}
|
136
|
+
let(:one_0022) {create_document("one|0022")}
|
137
|
+
let(:one_3) {create_document("one|3")}
|
138
|
+
let(:two_two) {create_document("two|two")}
|
139
|
+
let(:three_empty) {create_document("three|")}
|
140
|
+
|
141
|
+
before(:all) do
|
142
|
+
[one_001, one_002, one_0021, one_0022, one_3, two_two, three_empty, three_empty]
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when range is a single value" do
|
146
|
+
context "when the doc exists" do
|
147
|
+
it "returns a one-element list with the doc's model instance" do
|
148
|
+
set_of_keys(adapter.query(random_id("one"), "001")).should == set_of_keys([one_001])
|
149
|
+
set_of_keys(adapter.query(random_id("three"), "")).should == set_of_keys([three_empty])
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "when the doc does not exists" do
|
154
|
+
it "returns an empty list" do
|
155
|
+
adapter.query(random_id("unknown_hash"), "001").should == []
|
156
|
+
adapter.query(random_id("one"), "unknown_range").should == []
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when range is a Range" do
|
162
|
+
|
163
|
+
it "returns documents exactly matching the range border" do
|
164
|
+
set_of_keys(adapter.query(random_id("one"), Range.new("0021", "0022"))).
|
165
|
+
should == set_of_keys([one_0021, one_0022])
|
166
|
+
set_of_keys(adapter.query(random_id("three"), Range.new("", ""))).
|
167
|
+
should == set_of_keys([three_empty])
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns all documents with a range value within the range" do
|
171
|
+
set_of_keys(adapter.query(random_id("one"), Range.new("0021", "0022"))).
|
172
|
+
should == set_of_keys([one_0021, one_0022])
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when there is no doc within the range" do
|
176
|
+
it "returns an empty list" do
|
177
|
+
adapter.query(random_id("one"), Range.new("5", "8")).
|
178
|
+
should == []
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when range is ["", "~"]' do
|
183
|
+
it "does not miss a document for the hash value" do
|
184
|
+
set_of_keys(adapter.query(random_id("one"), Range.new("", "~"))).
|
185
|
+
should == set_of_keys([one_001, one_002, one_0021, one_0022, one_3])
|
186
|
+
set_of_keys(adapter.query(random_id("three"), Range.new("", "~"))).
|
187
|
+
should == set_of_keys([three_empty])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when there is no doc with the hash value" do
|
193
|
+
it "returns an empty list" do
|
194
|
+
adapter.query(random_id("none_of_these"), Range.new("", "~")).should == []
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
112
199
|
describe "destroying models" do
|
113
200
|
|
114
201
|
context "when the model has been created without id" do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Kvom::Lib::Json do
|
4
|
+
|
5
|
+
context "when MultiJson is new style (methods are dump and load)", :multi_json_version => ">= 1.3.0" do
|
6
|
+
it "is MultiJson" do
|
7
|
+
::Kvom::Lib::Json.should == ::MultiJson
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when MultiJson is old style (methods are encode and decode)", :multi_json_version => "< 1.3.0" do
|
12
|
+
|
13
|
+
let(:ruby_object) {[1, nil, true, false, [], {}]}
|
14
|
+
let(:json_string) {'[1,null,true,false,[],{}]'}
|
15
|
+
|
16
|
+
it "forwards .dump to MultiJson.encode" do
|
17
|
+
MultiJson.should_receive(:encode).with(ruby_object).and_return(json_string)
|
18
|
+
|
19
|
+
Kvom::Lib::Json.dump(ruby_object).should be_equal(json_string)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "forwards .load to MultiJson.decode" do
|
23
|
+
MultiJson.should_receive(:decode).with(json_string).and_return(ruby_object)
|
24
|
+
|
25
|
+
Kvom::Lib::Json.load(json_string).should be_equal(ruby_object)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,6 +24,8 @@ class TestModel < Kvom::Base
|
|
24
24
|
}
|
25
25
|
options[:partition] = "korb" if type == "partitioned_dynamo"
|
26
26
|
Kvom::Adapter::DynamodbAdapter.new(options)
|
27
|
+
when /filesystem/
|
28
|
+
Kvom::Adapter::FilesystemAdapter.new(:path => File.expand_path("../../tmp/fsa", __FILE__))
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -36,15 +38,25 @@ RSpec.configure do |config|
|
|
36
38
|
output = config.output_stream || $stdout
|
37
39
|
|
38
40
|
adapter_specified_and_different = lambda {|adapter_name|
|
39
|
-
if adapter_name
|
41
|
+
if adapter_name # no adapter_name => do not exclude
|
40
42
|
application_adapter = TestModel.adapter.class.to_s.demodulize
|
41
43
|
name = application_adapter.sub("Adapter", "").sub("db", "").downcase
|
42
|
-
if name != adapter_name.to_s
|
44
|
+
if name != adapter_name.to_s # same adapter name => do not exclude
|
43
45
|
output.print "a"
|
44
|
-
true
|
46
|
+
true # yes, exclude
|
45
47
|
end
|
46
48
|
end
|
47
49
|
}
|
50
|
+
|
51
|
+
multi_json_version_and_insufficient = lambda {|multi_json_version_restriction|
|
52
|
+
if multi_json_version_restriction
|
53
|
+
multi_json_version = Gem.loaded_specs["multi_json"].version
|
54
|
+
requirement = Gem::Requirement.create(multi_json_version_restriction)
|
55
|
+
!requirement.satisfied_by?(multi_json_version)
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
48
59
|
output.puts "Run filtered using adapter metadata (a - when skipped)"
|
49
60
|
config.filter_run_excluding :adapter => adapter_specified_and_different
|
61
|
+
config.filter_run_excluding :multi_json_version => multi_json_version_and_insufficient
|
50
62
|
end
|
data/tmp/.gitignore
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kvom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -134787116
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 6
|
@@ -9,12 +9,13 @@ version: !ruby/object:Gem::Version
|
|
9
9
|
- 0
|
10
10
|
- beta
|
11
11
|
- 200
|
12
|
-
-
|
13
|
-
- bdfa
|
12
|
+
- 856
|
14
13
|
- 8
|
15
14
|
- c
|
16
|
-
-
|
17
|
-
|
15
|
+
- 0
|
16
|
+
- fec
|
17
|
+
- 5
|
18
|
+
version: 6.8.0.beta.200.856.8c0fec5
|
18
19
|
platform: ruby
|
19
20
|
authors:
|
20
21
|
- Kristian Hanekamp, Infopark AG
|
@@ -22,69 +23,67 @@ autorequire:
|
|
22
23
|
bindir: bin
|
23
24
|
cert_chain: []
|
24
25
|
|
25
|
-
date: 2012-07-
|
26
|
+
date: 2012-07-23 00:00:00 +02:00
|
26
27
|
default_executable:
|
27
28
|
dependencies:
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
|
-
type: :development
|
30
30
|
requirement: &id001 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
hash:
|
35
|
+
hash: 1
|
36
36
|
segments:
|
37
|
-
-
|
38
|
-
|
39
|
-
- 0
|
40
|
-
version: 2.8.0
|
41
|
-
prerelease: false
|
42
|
-
name: rspec
|
37
|
+
- 1
|
38
|
+
version: "1"
|
43
39
|
version_requirements: *id001
|
40
|
+
name: multi_json
|
41
|
+
prerelease: false
|
42
|
+
type: :runtime
|
44
43
|
- !ruby/object:Gem::Dependency
|
45
|
-
type: :development
|
46
44
|
requirement: &id002 !ruby/object:Gem::Requirement
|
47
45
|
none: false
|
48
46
|
requirements:
|
49
47
|
- - ">="
|
50
48
|
- !ruby/object:Gem::Version
|
51
|
-
hash:
|
49
|
+
hash: 5
|
52
50
|
segments:
|
53
|
-
-
|
54
|
-
version: "
|
55
|
-
prerelease: false
|
56
|
-
name: helpful_configuration
|
51
|
+
- 3
|
52
|
+
version: "3"
|
57
53
|
version_requirements: *id002
|
58
|
-
|
54
|
+
name: activesupport
|
55
|
+
prerelease: false
|
59
56
|
type: :runtime
|
57
|
+
- !ruby/object:Gem::Dependency
|
60
58
|
requirement: &id003 !ruby/object:Gem::Requirement
|
61
59
|
none: false
|
62
60
|
requirements:
|
63
61
|
- - ">="
|
64
62
|
- !ruby/object:Gem::Version
|
65
|
-
hash:
|
63
|
+
hash: 5
|
66
64
|
segments:
|
67
|
-
-
|
68
|
-
version: "
|
69
|
-
prerelease: false
|
70
|
-
name: couchrest
|
65
|
+
- 3
|
66
|
+
version: "3"
|
71
67
|
version_requirements: *id003
|
72
|
-
|
68
|
+
name: activemodel
|
69
|
+
prerelease: false
|
73
70
|
type: :runtime
|
71
|
+
- !ruby/object:Gem::Dependency
|
74
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
75
73
|
none: false
|
76
74
|
requirements:
|
77
|
-
- -
|
75
|
+
- - ~>
|
78
76
|
- !ruby/object:Gem::Version
|
79
|
-
hash:
|
77
|
+
hash: 19
|
80
78
|
segments:
|
81
|
-
-
|
82
|
-
|
83
|
-
|
84
|
-
name: activemodel
|
79
|
+
- 2
|
80
|
+
- 8
|
81
|
+
version: "2.8"
|
85
82
|
version_requirements: *id004
|
83
|
+
name: rspec
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
|
-
type: :runtime
|
88
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
88
|
none: false
|
90
89
|
requirements:
|
@@ -94,11 +93,11 @@ dependencies:
|
|
94
93
|
segments:
|
95
94
|
- 0
|
96
95
|
version: "0"
|
97
|
-
prerelease: false
|
98
|
-
name: aws-sdk
|
99
96
|
version_requirements: *id005
|
97
|
+
name: helpful_configuration
|
98
|
+
prerelease: false
|
99
|
+
type: :development
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
|
-
type: :runtime
|
102
101
|
requirement: &id006 !ruby/object:Gem::Requirement
|
103
102
|
none: false
|
104
103
|
requirements:
|
@@ -108,23 +107,10 @@ dependencies:
|
|
108
107
|
segments:
|
109
108
|
- 0
|
110
109
|
version: "0"
|
111
|
-
prerelease: false
|
112
|
-
name: multi_json
|
113
110
|
version_requirements: *id006
|
114
|
-
-
|
115
|
-
type: :runtime
|
116
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
|
-
requirements:
|
119
|
-
- - ">="
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
hash: 3
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
version: "0"
|
111
|
+
name: yajl-ruby
|
125
112
|
prerelease: false
|
126
|
-
|
127
|
-
version_requirements: *id007
|
113
|
+
type: :development
|
128
114
|
description: Use it to build object models in ruby on top of a key value store.
|
129
115
|
email:
|
130
116
|
- kristian.hanekamp@infopark.de
|
@@ -146,8 +132,14 @@ files:
|
|
146
132
|
- lib/kvom/adapter/couchdb_document.rb
|
147
133
|
- lib/kvom/adapter/dynamodb_adapter.rb
|
148
134
|
- lib/kvom/adapter/dynamodb_document.rb
|
135
|
+
- lib/kvom/adapter/filesystem_adapter.rb
|
136
|
+
- lib/kvom/adapter/filesystem_document.rb
|
137
|
+
- lib/kvom/adapter/key_attributes_document.rb
|
149
138
|
- lib/kvom/base.rb
|
150
139
|
- lib/kvom/document.rb
|
140
|
+
- lib/kvom/lib.rb
|
141
|
+
- lib/kvom/lib/json.rb
|
142
|
+
- lib/kvom/lib/json_value.rb
|
151
143
|
- lib/kvom/model_identity.rb
|
152
144
|
- lib/kvom/not_found.rb
|
153
145
|
- lib/kvom/storage.rb
|
@@ -161,9 +153,11 @@ files:
|
|
161
153
|
- spec/adaptor/dynamodb_adaptor_spec.rb
|
162
154
|
- spec/adaptor/model_identity_spec.rb
|
163
155
|
- spec/cache_with_prefix_spec.rb
|
156
|
+
- spec/lib/json_spec.rb
|
164
157
|
- spec/spec_helper.rb
|
165
158
|
- spec/storage/file_system_spec.rb
|
166
159
|
- spec/storage/s3_spec.rb
|
160
|
+
- tmp/.gitignore
|
167
161
|
has_rdoc: true
|
168
162
|
homepage: ""
|
169
163
|
licenses: []
|
@@ -206,6 +200,7 @@ test_files:
|
|
206
200
|
- spec/adaptor/dynamodb_adaptor_spec.rb
|
207
201
|
- spec/adaptor/model_identity_spec.rb
|
208
202
|
- spec/cache_with_prefix_spec.rb
|
203
|
+
- spec/lib/json_spec.rb
|
209
204
|
- spec/spec_helper.rb
|
210
205
|
- spec/storage/file_system_spec.rb
|
211
206
|
- spec/storage/s3_spec.rb
|