daodalus-moped 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +72 -0
  5. data/LICENCE.md +9 -0
  6. data/README.md +316 -0
  7. data/Rakefile +8 -0
  8. data/daodalus-moped.gemspec +24 -0
  9. data/lib/daodalus.rb +29 -0
  10. data/lib/daodalus/connection.rb +19 -0
  11. data/lib/daodalus/dao.rb +35 -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 +31 -0
  24. data/lib/daodalus/dsl/query.rb +42 -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 +26 -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,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 = Moped::Session.new(['localhost:27017'])
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-moped
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russell Dunphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-02 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: moped
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: em-synchrony-moped
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-moped.gemspec
125
+ - lib/daodalus.rb
126
+ - lib/daodalus/connection.rb
127
+ - lib/daodalus/dao.rb
128
+ - lib/daodalus/dsl.rb
129
+ - lib/daodalus/dsl/aggregation/group.rb
130
+ - lib/daodalus/dsl/aggregation/limit.rb
131
+ - lib/daodalus/dsl/aggregation/match.rb
132
+ - lib/daodalus/dsl/aggregation/project.rb
133
+ - lib/daodalus/dsl/aggregation/skip.rb
134
+ - lib/daodalus/dsl/aggregation/sort.rb
135
+ - lib/daodalus/dsl/aggregation/unwind.rb
136
+ - lib/daodalus/dsl/aggregations.rb
137
+ - lib/daodalus/dsl/clause.rb
138
+ - lib/daodalus/dsl/matchers.rb
139
+ - lib/daodalus/dsl/queries.rb
140
+ - lib/daodalus/dsl/query.rb
141
+ - lib/daodalus/dsl/select.rb
142
+ - lib/daodalus/dsl/update.rb
143
+ - lib/daodalus/dsl/updates.rb
144
+ - lib/daodalus/dsl/where.rb
145
+ - lib/daodalus/invalid_connection_error.rb
146
+ - lib/daodalus/invalid_query_error.rb
147
+ - spec/lib/daodalus/connection_spec.rb
148
+ - spec/lib/daodalus/dao_spec.rb
149
+ - spec/lib/daodalus/dsl/aggregation/group_spec.rb
150
+ - spec/lib/daodalus/dsl/aggregation/limit_spec.rb
151
+ - spec/lib/daodalus/dsl/aggregation/match_spec.rb
152
+ - spec/lib/daodalus/dsl/aggregation/project_spec.rb
153
+ - spec/lib/daodalus/dsl/aggregation/skip_spec.rb
154
+ - spec/lib/daodalus/dsl/aggregation/sort_spec.rb
155
+ - spec/lib/daodalus/dsl/aggregation/unwind_spec.rb
156
+ - spec/lib/daodalus/dsl/clause_spec.rb
157
+ - spec/lib/daodalus/dsl/query_spec.rb
158
+ - spec/lib/daodalus/dsl/select_spec.rb
159
+ - spec/lib/daodalus/dsl/update_spec.rb
160
+ - spec/lib/daodalus/dsl/where_spec.rb
161
+ - spec/lib/daodalus/dsl_spec.rb
162
+ - spec/pointless_coverage_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/support/mongo_cleaner.rb
165
+ homepage: http://onthebeach.github.io/daodalus-moped
166
+ licenses: []
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 1.8.25
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Take the sting out of building complex MongoDB queries, updates and aggregations.
189
+ test_files:
190
+ - spec/lib/daodalus/connection_spec.rb
191
+ - spec/lib/daodalus/dao_spec.rb
192
+ - spec/lib/daodalus/dsl/aggregation/group_spec.rb
193
+ - spec/lib/daodalus/dsl/aggregation/limit_spec.rb
194
+ - spec/lib/daodalus/dsl/aggregation/match_spec.rb
195
+ - spec/lib/daodalus/dsl/aggregation/project_spec.rb
196
+ - spec/lib/daodalus/dsl/aggregation/skip_spec.rb
197
+ - spec/lib/daodalus/dsl/aggregation/sort_spec.rb
198
+ - spec/lib/daodalus/dsl/aggregation/unwind_spec.rb
199
+ - spec/lib/daodalus/dsl/clause_spec.rb
200
+ - spec/lib/daodalus/dsl/query_spec.rb
201
+ - spec/lib/daodalus/dsl/select_spec.rb
202
+ - spec/lib/daodalus/dsl/update_spec.rb
203
+ - spec/lib/daodalus/dsl/where_spec.rb
204
+ - spec/lib/daodalus/dsl_spec.rb
205
+ - spec/pointless_coverage_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/support/mongo_cleaner.rb
208
+ has_rdoc: