flipper-mongo 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - ree
5
+ - 1.9.3
6
+ notifications:
7
+ email: false
8
+ bundler_args: --without guard
9
+ before_script: sudo service mongodb status
10
+ services: mongodb
data/Gemfile CHANGED
@@ -2,19 +2,15 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
+ gem 'rspec'
6
+ gem 'timecop'
7
+ gem 'bson_ext'
8
+ gem 'mongo'
9
+ gem 'rack-test'
5
10
 
6
11
  group(:guard) do
7
12
  gem 'guard'
8
13
  gem 'guard-rspec'
9
14
  gem 'guard-bundler'
10
- gem 'growl'
15
+ gem 'rb-fsevent'
11
16
  end
12
-
13
- group(:test) do
14
- gem 'rspec'
15
- gem 'timecop'
16
- gem 'bson_ext'
17
- gem 'mongo'
18
- gem 'rack-test'
19
- end
20
-
@@ -14,5 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "flipper-mongo"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Flipper::Adapters::Mongo::VERSION
17
- gem.add_dependency 'flipper', '~> 0.2'
17
+ gem.add_dependency 'flipper', '~> 0.4'
18
18
  end
@@ -17,11 +17,11 @@ module Flipper
17
17
  end
18
18
 
19
19
  def write(key, value)
20
- update key, {'$set' => {'v' => value}}
20
+ update key, {'$set' => {'v' => value.to_s}}
21
21
  end
22
22
 
23
23
  def delete(key)
24
- @collection.remove criteria(key)
24
+ remove key
25
25
  end
26
26
 
27
27
  def set_members(key)
@@ -29,17 +29,19 @@ module Flipper
29
29
  end
30
30
 
31
31
  def set_add(key, value)
32
- update key, {'$addToSet' => {'v' => value}}
32
+ update key, {'$addToSet' => {'v' => value.to_s}}
33
33
  end
34
34
 
35
35
  def set_delete(key, value)
36
- update key, {'$pull' => {'v' => value}}
36
+ update key, {'$pull' => {'v' => value.to_s}}
37
37
  end
38
38
 
39
39
  private
40
40
 
41
41
  def find_one(key)
42
- if (doc = @collection.find_one(criteria(key)))
42
+ doc = @collection.find_one(criteria(key))
43
+
44
+ unless doc.nil?
43
45
  doc['v']
44
46
  end
45
47
  end
@@ -48,8 +50,12 @@ module Flipper
48
50
  @collection.update criteria(key), updates, @update_options
49
51
  end
50
52
 
53
+ def remove(key)
54
+ @collection.remove criteria(key)
55
+ end
56
+
51
57
  def criteria(key)
52
- {:_id => key}
58
+ {:_id => key.to_s}
53
59
  end
54
60
  end
55
61
  end
@@ -17,37 +17,40 @@ module Flipper
17
17
  end
18
18
 
19
19
  def read(key)
20
- source[key]
20
+ source[key.to_s]
21
21
  end
22
22
 
23
23
  def write(key, value)
24
- @collection.update @criteria, {'$set' => {key => value}}, @mongo_options
25
- @source[key] = value
24
+ value = value.to_s
25
+ @collection.update @criteria, {'$set' => {key.to_s => value}}, @mongo_options
26
+ @source[key.to_s] = value
26
27
  end
27
28
 
28
29
  def delete(key)
29
- @collection.update @criteria, {'$unset' => {key => 1}}, @mongo_options
30
- @source.delete key
30
+ @collection.update @criteria, {'$unset' => {key.to_s => 1}}, @mongo_options
31
+ @source.delete key.to_s
31
32
  end
32
33
 
33
34
  def set_members(key)
34
- members = source.fetch(key) { @source[key] = Set.new }
35
+ members = source.fetch(key.to_s) { @source[key.to_s] = Set.new }
35
36
 
36
37
  if members.is_a?(Array)
37
- @source[key] = members.to_set
38
+ @source[key.to_s] = members.to_set
38
39
  else
39
40
  members
40
41
  end
41
42
  end
42
43
 
43
44
  def set_add(key, value)
44
- @collection.update @criteria, {'$addToSet' => {key => value}}, @mongo_options
45
- set_members(key).add(value)
45
+ value = value.to_s
46
+ @collection.update @criteria, {'$addToSet' => {key.to_s => value}}, @mongo_options
47
+ set_members(key.to_s).add(value)
46
48
  end
47
49
 
48
50
  def set_delete(key, value)
49
- @collection.update @criteria, {'$pull' => {key => value}}, @mongo_options
50
- set_members(key).delete(value)
51
+ value = value.to_s
52
+ @collection.update @criteria, {'$pull' => {key.to_s => value}}, @mongo_options
53
+ set_members(key.to_s).delete(value)
51
54
  end
52
55
 
53
56
  def clear
@@ -1,7 +1,7 @@
1
1
  module Flipper
2
2
  module Adapters
3
3
  class Mongo
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -27,7 +27,7 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
27
27
 
28
28
  describe "loading document" do
29
29
  before do
30
- collection.update(criteria, {'$set' => {'foo' => 'bar', 'people' => [1, 2, 3]}}, options)
30
+ collection.update(criteria, {'$set' => {'foo' => 'bar', 'people' => ['1', '2', '3']}}, options)
31
31
  end
32
32
 
33
33
  it "only happens once" do
@@ -151,18 +151,18 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
151
151
  describe "#set_members" do
152
152
  context "existing key" do
153
153
  before do
154
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3], 'foo' => 'bar'}}, options)
154
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3'], 'foo' => 'bar'}}, options)
155
155
  @result = subject.set_members('people')
156
156
  end
157
157
 
158
158
  it "returns set" do
159
- @result.should eq(Set[1, 2, 3])
159
+ @result.should eq(Set['1', '2', '3'])
160
160
  end
161
161
 
162
162
  it "loads source hash" do
163
163
  source.should eq({
164
164
  '_id' => id,
165
- 'people' => Set[1, 2, 3],
165
+ 'people' => Set['1', '2', '3'],
166
166
  'foo' => 'bar',
167
167
  })
168
168
  end
@@ -170,7 +170,7 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
170
170
 
171
171
  context "missing key" do
172
172
  before do
173
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3]}}, options)
173
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3']}}, options)
174
174
  @result = subject.set_members('users')
175
175
  end
176
176
 
@@ -189,31 +189,31 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
189
189
  describe "#set_add" do
190
190
  context "existing key" do
191
191
  before do
192
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3]}}, options)
192
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3']}}, options)
193
193
  subject.set_add('people', 4)
194
194
  end
195
195
 
196
196
  it "adds value to set" do
197
- document.fetch('people').should eq([1, 2, 3, 4])
198
- source.fetch('people').should eq(Set[1, 2, 3, 4])
197
+ document.fetch('people').should eq(['1', '2', '3', '4'])
198
+ source.fetch('people').should eq(Set['1', '2', '3', '4'])
199
199
  end
200
200
  end
201
201
 
202
202
  context "missing key" do
203
203
  before do
204
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3]}}, options)
205
- subject.set_add('users', 1)
204
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3']}}, options)
205
+ subject.set_add('users', '1')
206
206
  end
207
207
 
208
208
  it "adds value to set" do
209
- document.fetch('users').should eq([1])
210
- source.fetch('users').should eq(Set[1])
209
+ document.fetch('users').should eq(['1'])
210
+ source.fetch('users').should eq(Set['1'])
211
211
  end
212
212
  end
213
213
 
214
214
  context "missing document" do
215
215
  before do
216
- subject.set_add('people', 1)
216
+ subject.set_add('people', '1')
217
217
  end
218
218
 
219
219
  it "creates document" do
@@ -221,8 +221,8 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
221
221
  end
222
222
 
223
223
  it "adds value to set" do
224
- document.fetch('people').should eq([1])
225
- source.fetch('people').should eq(Set[1])
224
+ document.fetch('people').should eq(['1'])
225
+ source.fetch('people').should eq(Set['1'])
226
226
  end
227
227
  end
228
228
  end
@@ -230,23 +230,23 @@ describe Flipper::Adapters::MongoSingleDocument::Document do
230
230
  describe "#set_delete" do
231
231
  context "existing key" do
232
232
  before do
233
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3]}}, options)
234
- subject.set_delete 'people', 3
233
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3']}}, options)
234
+ subject.set_delete 'people', '3'
235
235
  end
236
236
 
237
237
  it "removes value to key" do
238
- document.fetch('people').should eq([1, 2])
239
- source.fetch('people').should eq(Set[1, 2])
238
+ document.fetch('people').should eq(['1', '2'])
239
+ source.fetch('people').should eq(Set['1', '2'])
240
240
  end
241
241
  end
242
242
 
243
243
  context "missing key" do
244
244
  before do
245
- collection.update(criteria, {'$set' => {'people' => [1, 2, 3]}}, options)
245
+ collection.update(criteria, {'$set' => {'people' => ['1', '2', '3']}}, options)
246
246
  end
247
247
 
248
248
  it "does not error" do
249
- expect { subject.set_delete 'foo', 1 }.to_not raise_error
249
+ expect { subject.set_delete 'foo', '1' }.to_not raise_error
250
250
  end
251
251
  end
252
252
 
@@ -15,7 +15,7 @@ describe Flipper::Adapters::MongoSingleDocument do
15
15
 
16
16
  def read_key(key)
17
17
  if (doc = collection.find_one(criteria))
18
- value = doc[key]
18
+ value = doc[key.to_s]
19
19
 
20
20
  if value.is_a?(::Array)
21
21
  value = value.to_set
@@ -26,12 +26,14 @@ describe Flipper::Adapters::MongoSingleDocument do
26
26
  end
27
27
 
28
28
  def write_key(key, value)
29
- if value.is_a?(::Set)
30
- value = value.to_a
29
+ value = if value.is_a?(::Set)
30
+ value.to_a.map(&:to_s)
31
+ else
32
+ value.to_s
31
33
  end
32
34
 
33
35
  options = {:upsert => true}
34
- updates = {'$set' => {key => value}}
36
+ updates = {'$set' => {key.to_s => value}}
35
37
  collection.update criteria, updates, options
36
38
  end
37
39
 
@@ -13,7 +13,7 @@ describe Flipper::Adapters::Mongo do
13
13
  end
14
14
 
15
15
  def read_key(key)
16
- if (doc = collection.find_one(:_id => key))
16
+ if (doc = collection.find_one(:_id => key.to_s))
17
17
  value = doc['v']
18
18
 
19
19
  if value.is_a?(::Array)
@@ -25,11 +25,13 @@ describe Flipper::Adapters::Mongo do
25
25
  end
26
26
 
27
27
  def write_key(key, value)
28
- if value.is_a?(::Set)
29
- value = value.to_a
28
+ value = if value.is_a?(::Set)
29
+ value.to_a.map(&:to_s)
30
+ else
31
+ value.to_s
30
32
  end
31
33
 
32
- criteria = {:_id => key}
34
+ criteria = {:_id => key.to_s}
33
35
  updates = {'$set' => {'v' => value}}
34
36
  options = {:upsert => true}
35
37
  collection.update criteria, updates, options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: flipper
16
- requirement: &70110164650060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0.2'
21
+ version: '0.4'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70110164650060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.4'
25
30
  description: Mongo adapter for Flipper
26
31
  email:
27
32
  - nunemaker@gmail.com
@@ -30,6 +35,7 @@ extensions: []
30
35
  extra_rdoc_files: []
31
36
  files:
32
37
  - .gitignore
38
+ - .travis.yml
33
39
  - Gemfile
34
40
  - Guardfile
35
41
  - LICENSE
@@ -62,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
68
  version: '0'
63
69
  segments:
64
70
  - 0
65
- hash: -3406714501289693291
71
+ hash: 1196015138740871413
66
72
  required_rubygems_version: !ruby/object:Gem::Requirement
67
73
  none: false
68
74
  requirements:
@@ -71,10 +77,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
77
  version: '0'
72
78
  segments:
73
79
  - 0
74
- hash: -3406714501289693291
80
+ hash: 1196015138740871413
75
81
  requirements: []
76
82
  rubyforge_project:
77
- rubygems_version: 1.8.10
83
+ rubygems_version: 1.8.23
78
84
  signing_key:
79
85
  specification_version: 3
80
86
  summary: Mongo adapter for Flipper