daodalus 0.1.1

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.
Files changed (49) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +65 -0
  5. data/LICENCE.md +9 -0
  6. data/README.md +316 -0
  7. data/Rakefile +8 -0
  8. data/daodalus.gemspec +23 -0
  9. data/lib/daodalus.rb +29 -0
  10. data/lib/daodalus/connection.rb +19 -0
  11. data/lib/daodalus/dao.rb +41 -0
  12. data/lib/daodalus/dsl.rb +21 -0
  13. data/lib/daodalus/dsl/aggregation/group.rb +88 -0
  14. data/lib/daodalus/dsl/aggregation/limit.rb +23 -0
  15. data/lib/daodalus/dsl/aggregation/match.rb +35 -0
  16. data/lib/daodalus/dsl/aggregation/project.rb +79 -0
  17. data/lib/daodalus/dsl/aggregation/skip.rb +23 -0
  18. data/lib/daodalus/dsl/aggregation/sort.rb +29 -0
  19. data/lib/daodalus/dsl/aggregation/unwind.rb +23 -0
  20. data/lib/daodalus/dsl/aggregations.rb +44 -0
  21. data/lib/daodalus/dsl/clause.rb +19 -0
  22. data/lib/daodalus/dsl/matchers.rb +87 -0
  23. data/lib/daodalus/dsl/queries.rb +29 -0
  24. data/lib/daodalus/dsl/query.rb +46 -0
  25. data/lib/daodalus/dsl/select.rb +43 -0
  26. data/lib/daodalus/dsl/update.rb +86 -0
  27. data/lib/daodalus/dsl/updates.rb +71 -0
  28. data/lib/daodalus/dsl/where.rb +30 -0
  29. data/lib/daodalus/invalid_connection_error.rb +7 -0
  30. data/lib/daodalus/invalid_query_error.rb +4 -0
  31. data/spec/lib/daodalus/connection_spec.rb +22 -0
  32. data/spec/lib/daodalus/dao_spec.rb +34 -0
  33. data/spec/lib/daodalus/dsl/aggregation/group_spec.rb +92 -0
  34. data/spec/lib/daodalus/dsl/aggregation/limit_spec.rb +22 -0
  35. data/spec/lib/daodalus/dsl/aggregation/match_spec.rb +32 -0
  36. data/spec/lib/daodalus/dsl/aggregation/project_spec.rb +74 -0
  37. data/spec/lib/daodalus/dsl/aggregation/skip_spec.rb +22 -0
  38. data/spec/lib/daodalus/dsl/aggregation/sort_spec.rb +36 -0
  39. data/spec/lib/daodalus/dsl/aggregation/unwind_spec.rb +24 -0
  40. data/spec/lib/daodalus/dsl/clause_spec.rb +22 -0
  41. data/spec/lib/daodalus/dsl/query_spec.rb +35 -0
  42. data/spec/lib/daodalus/dsl/select_spec.rb +46 -0
  43. data/spec/lib/daodalus/dsl/update_spec.rb +113 -0
  44. data/spec/lib/daodalus/dsl/where_spec.rb +133 -0
  45. data/spec/lib/daodalus/dsl_spec.rb +12 -0
  46. data/spec/pointless_coverage_spec.rb +9 -0
  47. data/spec/spec_helper.rb +18 -0
  48. data/spec/support/mongo_cleaner.rb +12 -0
  49. metadata +208 -0
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ module Daodalus
4
+ module DSL
5
+ describe Update do
6
+
7
+ let (:dao) { DAO.new(:animalhouse, :cats) }
8
+
9
+ before do
10
+ dao.insert('name' => 'Terry',
11
+ 'paws' => 3,
12
+ 'likes' => ['tuna', 'catnip'],
13
+ 'lives' => [1,2,3,4,5,6,7,8,9],
14
+ 'foods' => [{'type' => 'dry', 'name' => 'go cat'},
15
+ {'type' => 'wet', 'name' => 'whiskas'}])
16
+ end
17
+
18
+ it 'can perform upserts' do
19
+ dao.set(paws: 3).where(:name).eq('Charlie').upsert
20
+ dao.where(:name).eq('Charlie').find_one.value.merge('_id' => 1).should eq ({
21
+ '_id' => 1,
22
+ "name"=>"Charlie", "paws"=>3
23
+ })
24
+ end
25
+
26
+ it 'can perform find_and_modifys' do
27
+ dao.inc(:paws).where(:name).eq('Terry').find_and_modify
28
+ dao.where(:name).eq('Terry').find_one.value.merge('_id' => 1).should eq ({
29
+ '_id' => 1,
30
+ "name"=>"Terry", "paws"=>4, "likes"=>["tuna", "catnip"], "lives"=>[1, 2, 3, 4, 5, 6, 7, 8, 9], "foods"=>[{"type"=>"dry", "name"=>"go cat"}, {"type"=>"wet", "name"=>"whiskas"}]
31
+ })
32
+ end
33
+
34
+ it 'implements #set' do
35
+ dao.set(name: 'Terrence', paws: 2).update
36
+ dao.find_one.value.fetch('paws').should eq 2
37
+ dao.find_one.value.fetch('name').should eq 'Terrence'
38
+ end
39
+
40
+ it 'implements #unset' do
41
+ dao.unset(:name, :likes).update
42
+ dao.find_one.value.fetch('names', nil).should be_nil
43
+ dao.find_one.value.fetch('likes', nil).should be_nil
44
+ end
45
+
46
+ it 'implements #inc' do
47
+ dao.inc(:paws).update
48
+ dao.find_one.value.fetch('paws').should eq 4
49
+ end
50
+
51
+ it 'implements #dec' do
52
+ dao.dec(:paws, 2).update
53
+ dao.find_one.value.fetch('paws').should eq 1
54
+ end
55
+
56
+ it 'implements #rename' do
57
+ dao.rename(:paws, :feet).update
58
+ dao.find_one.value.fetch('feet').should eq 3
59
+ end
60
+
61
+ it 'implements #push' do
62
+ dao.push(:likes, 'food').update
63
+ dao.push(:likes, 'Marxist political economics', 'cake').update
64
+ dao.find_one.value.fetch('likes').should include 'Marxist political economics'
65
+ dao.find_one.value.fetch('likes').should include 'cake'
66
+ dao.find_one.value.fetch('likes').should include 'food'
67
+ end
68
+
69
+ it 'implements #pushAll' do
70
+ dao.push_all(:likes, ['Marxist political economics', 'cake']).update
71
+ dao.find_one.value.fetch('likes').should include 'Marxist political economics'
72
+ dao.find_one.value.fetch('likes').should include 'cake'
73
+ end
74
+
75
+ it 'implements #add_to_set' do
76
+ dao.add_to_set(:likes, 'cake').update
77
+ dao.add_to_set(:likes, 'tuna', 'cake', 'cake').update
78
+ dao.find_one.value.fetch('likes').should eq ['tuna', 'catnip', 'cake']
79
+ end
80
+
81
+ it 'implements #add_each_to_set' do
82
+ dao.add_each_to_set(:likes, ['tuna', 'cake', 'cake']).update
83
+ dao.find_one.value.fetch('likes').should eq ['tuna', 'catnip', 'cake']
84
+ end
85
+
86
+ it 'implements #pop_first' do
87
+ dao.pop_first(:likes).update
88
+ dao.find_one.value.fetch('likes').should eq ['catnip']
89
+ end
90
+
91
+ it 'implements #pop_last' do
92
+ dao.pop_last(:likes).update
93
+ dao.find_one.value.fetch('likes').should eq ['tuna']
94
+ end
95
+
96
+ it 'implements #pull' do
97
+ dao.pull(:likes, 'tuna').update
98
+ dao.find_one.value.fetch('likes').should eq ['catnip']
99
+ end
100
+
101
+ it 'allows passing multipl values to #pull' do
102
+ dao.pull(:likes, 'tuna', 'catnip').update
103
+ dao.find_one.value.fetch('likes').should eq []
104
+ end
105
+
106
+ it 'implements #pull_all' do
107
+ dao.pull_all(:likes, ['catnip', 'tuna']).update
108
+ dao.find_one.value.fetch('likes').should eq []
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ module Daodalus
4
+ module DSL
5
+ describe Where do
6
+
7
+ let (:dao) { DAO.new(:animalhouse, :cats) }
8
+
9
+ before do
10
+ dao.insert('name' => 'Terry',
11
+ 'paws' => 3,
12
+ 'likes' => ['tuna', 'catnip'],
13
+ 'foods' => [{'type' => 'dry', 'name' => 'go cat'},
14
+ {'type' => 'wet', 'name' => 'whiskas'}])
15
+ end
16
+
17
+ it 'can test for equality' do
18
+ dao.where(:name).eq('Terry').find.should have(1).item
19
+ end
20
+
21
+ it 'allows chaining of multiple clauses' do
22
+ dao.where(:name).eq('Terry').and(:paws).eq(3).find_one.should be_some
23
+ end
24
+
25
+ it 'excludes documents that do not match' do
26
+ dao.where(:name).eq('Terry').and(:paws).eq(77).find_one.should be_none
27
+ end
28
+
29
+ it 'can test for inequality' do
30
+ dao.where(:name).ne('Jennifer').find_one.should be_some
31
+ dao.where(:name).ne('Terry').find_one.should be_none
32
+ end
33
+
34
+ it 'implements #lt' do
35
+ dao.where(:paws).lt(4).find_one.should be_some
36
+ dao.where(:paws).lt(3).find_one.should be_none
37
+ end
38
+
39
+ it 'implements #gt' do
40
+ dao.where(:paws).gt(4).find_one.should be_none
41
+ dao.where(:paws).gt(2).find_one.should be_some
42
+ end
43
+
44
+ it 'implements #lte' do
45
+ dao.where(:paws).lte(3).find_one.should be_some
46
+ dao.where(:paws).lte(2).find_one.should be_none
47
+ end
48
+
49
+ it 'implements #gte' do
50
+ dao.where(:paws).gte(3).find_one.should be_some
51
+ dao.where(:paws).gte(4).find_one.should be_none
52
+ end
53
+
54
+ it 'implements #in' do
55
+ dao.where(:paws).in(3, 5).find_one.should be_some
56
+ dao.where(:paws).in(4, 1).find_one.should be_none
57
+ end
58
+
59
+ it 'implements #nin' do
60
+ dao.where(:paws).nin(2, 5).find_one.should be_some
61
+ dao.where(:paws).nin(4, 3).find_one.should be_none
62
+ end
63
+
64
+ it 'implements #all' do
65
+ dao.where(:likes).all('catnip', 'tuna').find_one.should be_some
66
+ dao.where(:likes).all('catnip', 'dogs').find_one.should be_none
67
+ end
68
+
69
+ it 'implements #size' do
70
+ dao.where(:likes).size(2).find_one.should be_some
71
+ dao.where(:likes).size(3).find_one.should be_none
72
+ end
73
+
74
+ it 'implements #exists' do
75
+ dao.where(:paws).exists.find_one.should be_some
76
+ dao.where(:horns).exists.find_one.should be_none
77
+ end
78
+
79
+ it 'can also check for non-existence' do
80
+ dao.where(:horns).does_not_exist.find_one.should be_some
81
+ dao.where(:paws).does_not_exist.find_one.should be_none
82
+ end
83
+
84
+ it 'implements #not' do
85
+ dao.where(:paws).not.less_than(3).find_one.should be_some
86
+ dao.where(:paws).not.eq(3).find_one.should be_none
87
+ end
88
+
89
+ it 'implements #any' do
90
+ dao.where.any(
91
+ dao.where(:likes).size(14),
92
+ dao.where(:likes).eq('tuna'),
93
+ ).find_one.should be_some
94
+
95
+ dao.where.any(
96
+ dao.where(:likes).size(14),
97
+ dao.where(:likes).eq('dogs'),
98
+ ).find_one.should be_none
99
+ end
100
+
101
+ it 'implements #none' do
102
+ dao.where.none(
103
+ dao.where(:likes).size(3),
104
+ dao.where(:likes).eq('dogs'),
105
+ ).find_one.should be_some
106
+
107
+ dao.where.none(
108
+ dao.where(:likes).size(7),
109
+ dao.where(:likes).eq('catnip'),
110
+ ).find_one.should be_none
111
+ end
112
+
113
+ it 'implements #elem_match' do
114
+ dao.where(:foods).elem_match(
115
+ dao.where(:type).eq(:wet).and(:name).eq('whiskas')
116
+ ).find_one.should be_some
117
+
118
+ dao.where(:foods).elem_match(
119
+ dao.where(:type).eq(:dry).and(:name).eq('whiskas')
120
+ ).find_one.should be_none
121
+ end
122
+
123
+ it 'can be chained with select clauses' do
124
+ dao.where(:name).eq('Terry').select(:paws).find_one.value.fetch('paws').should eq 3
125
+ end
126
+
127
+ it 'can be passed a hash directly' do
128
+ dao.where(name: 'Terry', paws: 3).find_one.should be_some
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ module Daodalus
4
+ describe DSL do
5
+
6
+ let (:dao) { DAO.new(:animalhouse, :cats) }
7
+
8
+ it 'can perform queries with a where clause' do
9
+ dao.where(:paws).eq(-1).find.to_a.should eq []
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "a pathetic attempt to get the hits/line up to 10x per line" do
4
+ it 'is pathetic' do
5
+ 142.times do
6
+ Daodalus::DAO.new(:animalhouse, :cats)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/spec'
4
+ end
5
+
6
+ require 'rspec'
7
+ require 'daodalus'
8
+
9
+ require 'support/mongo_cleaner'
10
+
11
+ RSpec.configure do |config|
12
+ config.order = :rand
13
+ config.color_enabled = true
14
+ config.before(:each) { MongoCleaner.clean }
15
+ end
16
+
17
+ conn = Mongo::MongoClient.new('localhost', 27017, pool_size: 5, pool_timeout: 5)
18
+ Daodalus::Connection.register(conn)
@@ -0,0 +1,12 @@
1
+ module MongoCleaner
2
+ extend self
3
+
4
+ def clean
5
+ dao.remove
6
+ end
7
+
8
+ def dao
9
+ @dao ||= Daodalus::DAO.new(:animalhouse, :cats)
10
+ end
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daodalus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russell Dunphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: id
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: optional
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mongo
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bson_ext
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Take the sting out of building complex MongoDB queries, updates and aggregations.
111
+ email:
112
+ - russell.dunphy@onthebeach.co.uk
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .travis.yml
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENCE.md
122
+ - README.md
123
+ - Rakefile
124
+ - daodalus-0.1.0.gem
125
+ - daodalus.gemspec
126
+ - lib/daodalus.rb
127
+ - lib/daodalus/connection.rb
128
+ - lib/daodalus/dao.rb
129
+ - lib/daodalus/dsl.rb
130
+ - lib/daodalus/dsl/aggregation/group.rb
131
+ - lib/daodalus/dsl/aggregation/limit.rb
132
+ - lib/daodalus/dsl/aggregation/match.rb
133
+ - lib/daodalus/dsl/aggregation/project.rb
134
+ - lib/daodalus/dsl/aggregation/skip.rb
135
+ - lib/daodalus/dsl/aggregation/sort.rb
136
+ - lib/daodalus/dsl/aggregation/unwind.rb
137
+ - lib/daodalus/dsl/aggregations.rb
138
+ - lib/daodalus/dsl/clause.rb
139
+ - lib/daodalus/dsl/matchers.rb
140
+ - lib/daodalus/dsl/queries.rb
141
+ - lib/daodalus/dsl/query.rb
142
+ - lib/daodalus/dsl/select.rb
143
+ - lib/daodalus/dsl/update.rb
144
+ - lib/daodalus/dsl/updates.rb
145
+ - lib/daodalus/dsl/where.rb
146
+ - lib/daodalus/invalid_connection_error.rb
147
+ - lib/daodalus/invalid_query_error.rb
148
+ - spec/lib/daodalus/connection_spec.rb
149
+ - spec/lib/daodalus/dao_spec.rb
150
+ - spec/lib/daodalus/dsl/aggregation/group_spec.rb
151
+ - spec/lib/daodalus/dsl/aggregation/limit_spec.rb
152
+ - spec/lib/daodalus/dsl/aggregation/match_spec.rb
153
+ - spec/lib/daodalus/dsl/aggregation/project_spec.rb
154
+ - spec/lib/daodalus/dsl/aggregation/skip_spec.rb
155
+ - spec/lib/daodalus/dsl/aggregation/sort_spec.rb
156
+ - spec/lib/daodalus/dsl/aggregation/unwind_spec.rb
157
+ - spec/lib/daodalus/dsl/clause_spec.rb
158
+ - spec/lib/daodalus/dsl/query_spec.rb
159
+ - spec/lib/daodalus/dsl/select_spec.rb
160
+ - spec/lib/daodalus/dsl/update_spec.rb
161
+ - spec/lib/daodalus/dsl/where_spec.rb
162
+ - spec/lib/daodalus/dsl_spec.rb
163
+ - spec/pointless_coverage_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/support/mongo_cleaner.rb
166
+ homepage: http://onthebeach.github.io/daodalus
167
+ licenses: []
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.23
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Take the sting out of building complex MongoDB queries, updates and aggregations.
190
+ test_files:
191
+ - spec/lib/daodalus/connection_spec.rb
192
+ - spec/lib/daodalus/dao_spec.rb
193
+ - spec/lib/daodalus/dsl/aggregation/group_spec.rb
194
+ - spec/lib/daodalus/dsl/aggregation/limit_spec.rb
195
+ - spec/lib/daodalus/dsl/aggregation/match_spec.rb
196
+ - spec/lib/daodalus/dsl/aggregation/project_spec.rb
197
+ - spec/lib/daodalus/dsl/aggregation/skip_spec.rb
198
+ - spec/lib/daodalus/dsl/aggregation/sort_spec.rb
199
+ - spec/lib/daodalus/dsl/aggregation/unwind_spec.rb
200
+ - spec/lib/daodalus/dsl/clause_spec.rb
201
+ - spec/lib/daodalus/dsl/query_spec.rb
202
+ - spec/lib/daodalus/dsl/select_spec.rb
203
+ - spec/lib/daodalus/dsl/update_spec.rb
204
+ - spec/lib/daodalus/dsl/where_spec.rb
205
+ - spec/lib/daodalus/dsl_spec.rb
206
+ - spec/pointless_coverage_spec.rb
207
+ - spec/spec_helper.rb
208
+ - spec/support/mongo_cleaner.rb