mongo_adaptor 0.0.17 → 1.0.0
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/.travis.yml +5 -2
- data/Gemfile +0 -4
- data/lib/mongo_adaptor.rb +15 -14
- data/lib/mongo_adaptor/version.rb +1 -1
- data/mongo_adaptor.gemspec +2 -3
- data/spec/mongo_adaptor_spec.rb +33 -23
- metadata +11 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a962c576b77d36bb59564fa73d92d4edf380cc6
|
4
|
+
data.tar.gz: 982bfeab74870bf4738560fd955fc8e200d8a934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274fbce2383d1ad46b5b4adacee9fecdb22f5aeff66799b784725f6ad6e4ae9689edff12dd78bb3fe0418a79021454a087fc788f18219f65c6acfbbdfda2fcc8
|
7
|
+
data.tar.gz: b94804b5b46e3c7619075fe7dddb4d0a607a307d29eba1c64c8abafde606de7800e2dc577e16987ece343150517abd32b3032bc4f6147cf2e0ec3304b1dfc0d1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/mongo_adaptor.rb
CHANGED
@@ -19,15 +19,15 @@ class MongoAdaptor
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def insert model
|
22
|
-
@collection.
|
22
|
+
@collection.insert_one process(model), safe_mode
|
23
23
|
end
|
24
24
|
|
25
25
|
def upsert model, query = { "_id" => model.id }
|
26
|
-
@collection.
|
26
|
+
@collection.update_one query, set(process(model)), safe_mode.merge(upsert_mode true)
|
27
27
|
end
|
28
28
|
|
29
29
|
def update model, query = { "_id" => model.id }
|
30
|
-
@collection.
|
30
|
+
@collection.update_one query, set(process(model)), safe_mode.merge(upsert_mode false)
|
31
31
|
end
|
32
32
|
|
33
33
|
def execute query_or_model, command, options = {}
|
@@ -36,30 +36,31 @@ class MongoAdaptor
|
|
36
36
|
else
|
37
37
|
query = { "_id" => query_or_model.id }
|
38
38
|
end
|
39
|
-
@collection.
|
39
|
+
@collection.update_one query, command, safe_mode.merge(upsert_mode false).merge(options)
|
40
40
|
end
|
41
41
|
|
42
42
|
def fetch selector = {}, opts = {}
|
43
|
-
@collection.
|
43
|
+
build(@collection.find(selector, { :fields => fields }.merge(opts)).first)
|
44
44
|
end
|
45
45
|
|
46
46
|
def remove selector = {}, opts = {}
|
47
|
-
@collection.
|
47
|
+
@collection.delete_many selector, opts
|
48
48
|
end
|
49
49
|
|
50
50
|
def find selector = {}, opts = {}
|
51
|
-
@collection.find
|
51
|
+
@collection.find(selector, { :fields => fields }.merge(opts)).map do |model|
|
52
|
+
build model
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
private
|
55
57
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
58
|
+
def build result
|
59
|
+
return unless result
|
60
|
+
@klass.new.tap do |model|
|
61
|
+
model[:id] = result.delete('_id') if model.respond_to?(:id)
|
62
|
+
result.each do |field,value|
|
63
|
+
model[field] = value if fields.include?(field.to_s)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
data/mongo_adaptor.gemspec
CHANGED
@@ -15,10 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = MongoAdaptor::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'mongo'
|
19
|
-
gem.add_dependency 'mongo-configure'
|
18
|
+
gem.add_dependency 'mongo', '~> 2.4'
|
19
|
+
gem.add_dependency 'mongo-configure', '~> 2.0.0'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'rake'
|
22
22
|
gem.add_development_dependency 'rspec'
|
23
|
-
gem.add_development_dependency 'rspec-its'
|
24
23
|
end
|
data/spec/mongo_adaptor_spec.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require 'rspec/its'
|
2
1
|
require 'mongo_adaptor'
|
3
2
|
|
4
3
|
describe 'adapting structs into mongo' do
|
5
|
-
before
|
6
|
-
|
4
|
+
before do
|
5
|
+
Mongo::Logger.level = :info
|
6
|
+
Mongo::Configure.from_database 'mongo_adaptor_test'
|
7
|
+
end
|
8
|
+
|
9
|
+
after { Mongo::Configure.current.load.collections.select { |c| c.name !~ /^system\./ }.each &:delete_many }
|
7
10
|
|
8
11
|
describe 'db setup' do
|
9
12
|
it 'uses the configured database' do
|
@@ -29,7 +32,7 @@ describe 'adapting structs into mongo' do
|
|
29
32
|
|
30
33
|
shared_examples_for 'creates a document' do
|
31
34
|
it 'changes the number of items in the collection' do
|
32
|
-
expect { subject }.to change { collection.
|
35
|
+
expect { subject }.to change { collection.count }.by(1)
|
33
36
|
end
|
34
37
|
it 'generates an _id, ignoring any set key' do
|
35
38
|
subject
|
@@ -69,7 +72,7 @@ describe 'adapting structs into mongo' do
|
|
69
72
|
|
70
73
|
describe 'with an existing model' do
|
71
74
|
let(:model) { klass.new 'Test Model','Some Data',['Some Other Members'] }
|
72
|
-
let(:id) { collection.
|
75
|
+
let(:id) { collection.insert_one({ :name => 'My Model', :other => 'Some Value', :members => ['Some Members'] },{ :w => 1 }).inserted_id }
|
73
76
|
|
74
77
|
before do
|
75
78
|
model.id = id
|
@@ -79,10 +82,10 @@ describe 'adapting structs into mongo' do
|
|
79
82
|
let(:data) { collection.find({}).to_a[-1] }
|
80
83
|
|
81
84
|
it 'doesnt change the number of items in the collection' do
|
82
|
-
expect { subject }.to change { collection.
|
85
|
+
expect { subject }.to change { collection.count }.by(0)
|
83
86
|
end
|
84
87
|
it 'doesnt change the id' do
|
85
|
-
expect { subject }.to_not change { collection.
|
88
|
+
expect { subject }.to_not change { collection.find.first['_id'] }
|
86
89
|
end
|
87
90
|
it 'sets my fields and values' do
|
88
91
|
subject
|
@@ -105,16 +108,16 @@ describe 'adapting structs into mongo' do
|
|
105
108
|
|
106
109
|
describe 'to update it with a custom operation' do
|
107
110
|
let(:data) { collection.find({}).to_a[-1] }
|
108
|
-
|
111
|
+
let(:operation) { adaptor.execute model, "$push" => { "members" => "Some Other Members" } }
|
109
112
|
|
110
113
|
it 'doesnt change the number of items in the collection' do
|
111
|
-
expect {
|
114
|
+
expect { operation }.to change { collection.count }.by(0)
|
112
115
|
end
|
113
116
|
it 'doesnt change the id' do
|
114
|
-
expect {
|
117
|
+
expect { operation }.to_not change { collection.find.first['_id'] }
|
115
118
|
end
|
116
119
|
it 'executes my command' do
|
117
|
-
|
120
|
+
operation
|
118
121
|
expect(data['members']).to eq ['Some Members','Some Other Members']
|
119
122
|
end
|
120
123
|
it 'also can execute my command by query' do
|
@@ -124,12 +127,17 @@ describe 'adapting structs into mongo' do
|
|
124
127
|
end
|
125
128
|
|
126
129
|
describe 'to fetch it' do
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
let(:result) { adaptor.fetch({ :_id => id }) }
|
131
|
+
|
132
|
+
it "returns a class" do
|
133
|
+
expect(result).to be_a klass
|
134
|
+
end
|
135
|
+
specify "the classes fields are set correctly" do
|
136
|
+
expect(result.id).to eq id
|
137
|
+
expect(result.name).to eq 'My Model'
|
138
|
+
expect(result.other).to eq 'Some Value'
|
139
|
+
expect(result.members).to eq ['Some Members']
|
140
|
+
end
|
133
141
|
end
|
134
142
|
|
135
143
|
describe 'to remove it' do
|
@@ -143,21 +151,23 @@ describe 'adapting structs into mongo' do
|
|
143
151
|
describe 'finding multiples' do
|
144
152
|
before do
|
145
153
|
3.times do |i|
|
146
|
-
collection.
|
154
|
+
collection.insert_one({ :name => 'My Model', :other => i },{ :w => 1 })
|
147
155
|
end
|
148
156
|
3.times do |i|
|
149
|
-
collection.
|
157
|
+
collection.insert_one({ :name => 'Other Model', :other => i },{ :w => 1 })
|
150
158
|
end
|
151
159
|
end
|
152
160
|
|
153
|
-
|
161
|
+
let(:result) { adaptor.find({ :name => 'My Model' }) }
|
154
162
|
|
155
|
-
|
163
|
+
it 'returns 3 models' do
|
164
|
+
expect(result.count).to eq 3
|
165
|
+
end
|
156
166
|
it 'translates all to klass' do
|
157
|
-
expect(
|
167
|
+
expect(result.all? { |k| k.is_a? klass }).to be true
|
158
168
|
end
|
159
169
|
it 'gets them all' do
|
160
|
-
expect(
|
170
|
+
expect(result.map(&:other)).to eq [0,1,2]
|
161
171
|
end
|
162
172
|
it 'will pass along options' do
|
163
173
|
expect { adaptor.find({ :name => 'My Model' },{ :fields => { }}) }.to_not raise_error
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_adaptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongo-configure
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec-its
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
description: A simple mongo handler. Translates Structs into Mongo and back.
|
84
70
|
email:
|
85
71
|
- hello@jonrowe.co.uk
|
@@ -116,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
102
|
version: '0'
|
117
103
|
requirements: []
|
118
104
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.8
|
120
106
|
signing_key:
|
121
107
|
specification_version: 4
|
122
108
|
summary: A simple mongo handler. Translates Structs into Mongo and back.
|