inquery 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.releaser_config +4 -0
  4. data/.rubocop.yml +42 -0
  5. data/.travis.yml +9 -0
  6. data/.yardopts +1 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +21 -0
  9. data/README.md +288 -0
  10. data/RUBY_VERSION +1 -0
  11. data/Rakefile +36 -0
  12. data/VERSION +1 -0
  13. data/doc/Inquery.html +119 -0
  14. data/doc/Inquery/Exceptions.html +115 -0
  15. data/doc/Inquery/Exceptions/Base.html +127 -0
  16. data/doc/Inquery/Exceptions/InvalidRelation.html +131 -0
  17. data/doc/Inquery/Exceptions/UnknownCallSignature.html +131 -0
  18. data/doc/Inquery/Mixins.html +117 -0
  19. data/doc/Inquery/Mixins/RelationValidation.html +334 -0
  20. data/doc/Inquery/Mixins/RelationValidation/ClassMethods.html +190 -0
  21. data/doc/Inquery/Mixins/SchemaValidation.html +124 -0
  22. data/doc/Inquery/Mixins/SchemaValidation/ClassMethods.html +192 -0
  23. data/doc/Inquery/Query.html +736 -0
  24. data/doc/Inquery/Query/Chainable.html +476 -0
  25. data/doc/_index.html +254 -0
  26. data/doc/class_list.html +58 -0
  27. data/doc/css/common.css +1 -0
  28. data/doc/css/full_list.css +57 -0
  29. data/doc/css/style.css +339 -0
  30. data/doc/file.README.html +365 -0
  31. data/doc/file_list.html +60 -0
  32. data/doc/frames.html +26 -0
  33. data/doc/index.html +365 -0
  34. data/doc/js/app.js +219 -0
  35. data/doc/js/full_list.js +181 -0
  36. data/doc/js/jquery.js +4 -0
  37. data/doc/method_list.html +147 -0
  38. data/doc/top-level-namespace.html +112 -0
  39. data/inquery.gemspec +58 -0
  40. data/lib/inquery.rb +10 -0
  41. data/lib/inquery/exceptions.rb +7 -0
  42. data/lib/inquery/mixins/relation_validation.rb +100 -0
  43. data/lib/inquery/mixins/schema_validation.rb +27 -0
  44. data/lib/inquery/query.rb +50 -0
  45. data/lib/inquery/query/chainable.rb +53 -0
  46. data/test/db/models.rb +20 -0
  47. data/test/db/schema.rb +20 -0
  48. data/test/inquery/query/chainable_test.rb +67 -0
  49. data/test/inquery/query_test.rb +47 -0
  50. data/test/queries/group/fetch_as_json.rb +13 -0
  51. data/test/queries/group/fetch_green.rb +11 -0
  52. data/test/queries/group/fetch_red.rb +11 -0
  53. data/test/queries/group/filter_with_color.rb +12 -0
  54. data/test/queries/user/fetch_all.rb +9 -0
  55. data/test/queries/user/fetch_in_group.rb +13 -0
  56. data/test/queries/user/fetch_in_group_rel.rb +17 -0
  57. data/test/test_helper.rb +26 -0
  58. metadata +265 -0
@@ -0,0 +1,12 @@
1
+ module Queries
2
+ module Group
3
+ class FilterWithColor < Inquery::Query::Chainable
4
+ relation class: 'Group'
5
+ schema color: :string
6
+
7
+ def call
8
+ relation.where(color: osparams.color)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Queries
2
+ module User
3
+ class FetchAll < Inquery::Query
4
+ def call
5
+ ::User.all
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Queries
2
+ module User
3
+ class FetchInGroup < Inquery::Query
4
+ schema(
5
+ group_id: :integer
6
+ )
7
+
8
+ def call
9
+ ::Group.find(osparams.group_id).users
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Queries
2
+ module User
3
+ class FetchInGroupRel < Inquery::Query::Chainable
4
+ relation fields: 1
5
+
6
+ def call
7
+ return ::User.where(%(
8
+ id IN (
9
+ SELECT user_id FROM GROUPS_USERS WHERE group_id IN (
10
+ #{relation.to_sql}
11
+ )
12
+ )
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_record'
2
+ require 'minitest/autorun'
3
+ require 'inquery'
4
+ require 'db/models'
5
+
6
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
7
+
8
+ module TestHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ def setup_db
13
+ load File.dirname(__FILE__) + '/db/schema.rb'
14
+ end
15
+
16
+ def setup_base_data
17
+ Group.create!(name: 'Group 1', color: 'red')
18
+ Group.create!(name: 'Group 2', color: 'green')
19
+ Group.create!(name: 'Group 3', color: 'green')
20
+
21
+ User.create!(name: 'User 1', groups: Group.find([1, 2]))
22
+ User.create!(name: 'User 2', groups: Group.find([1, 3]))
23
+ User.create!(name: 'User 3', groups: Group.find([2]))
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,265 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inquery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sitrox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
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
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.35.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.35.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activesupport
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: activerecord
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: schemacop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.1
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.1
167
+ description:
168
+ email:
169
+ executables: []
170
+ extensions: []
171
+ extra_rdoc_files: []
172
+ files:
173
+ - ".gitignore"
174
+ - ".releaser_config"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - ".yardopts"
178
+ - Gemfile
179
+ - LICENSE
180
+ - README.md
181
+ - RUBY_VERSION
182
+ - Rakefile
183
+ - VERSION
184
+ - doc/Inquery.html
185
+ - doc/Inquery/Exceptions.html
186
+ - doc/Inquery/Exceptions/Base.html
187
+ - doc/Inquery/Exceptions/InvalidRelation.html
188
+ - doc/Inquery/Exceptions/UnknownCallSignature.html
189
+ - doc/Inquery/Mixins.html
190
+ - doc/Inquery/Mixins/RelationValidation.html
191
+ - doc/Inquery/Mixins/RelationValidation/ClassMethods.html
192
+ - doc/Inquery/Mixins/SchemaValidation.html
193
+ - doc/Inquery/Mixins/SchemaValidation/ClassMethods.html
194
+ - doc/Inquery/Query.html
195
+ - doc/Inquery/Query/Chainable.html
196
+ - doc/_index.html
197
+ - doc/class_list.html
198
+ - doc/css/common.css
199
+ - doc/css/full_list.css
200
+ - doc/css/style.css
201
+ - doc/file.README.html
202
+ - doc/file_list.html
203
+ - doc/frames.html
204
+ - doc/index.html
205
+ - doc/js/app.js
206
+ - doc/js/full_list.js
207
+ - doc/js/jquery.js
208
+ - doc/method_list.html
209
+ - doc/top-level-namespace.html
210
+ - inquery.gemspec
211
+ - lib/inquery.rb
212
+ - lib/inquery/exceptions.rb
213
+ - lib/inquery/mixins/relation_validation.rb
214
+ - lib/inquery/mixins/schema_validation.rb
215
+ - lib/inquery/query.rb
216
+ - lib/inquery/query/chainable.rb
217
+ - test/db/models.rb
218
+ - test/db/schema.rb
219
+ - test/inquery/query/chainable_test.rb
220
+ - test/inquery/query_test.rb
221
+ - test/queries/group/fetch_as_json.rb
222
+ - test/queries/group/fetch_green.rb
223
+ - test/queries/group/fetch_red.rb
224
+ - test/queries/group/filter_with_color.rb
225
+ - test/queries/user/fetch_all.rb
226
+ - test/queries/user/fetch_in_group.rb
227
+ - test/queries/user/fetch_in_group_rel.rb
228
+ - test/test_helper.rb
229
+ homepage:
230
+ licenses: []
231
+ metadata: {}
232
+ post_install_message:
233
+ rdoc_options: []
234
+ require_paths:
235
+ - lib
236
+ required_ruby_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ required_rubygems_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ requirements: []
247
+ rubyforge_project:
248
+ rubygems_version: 2.6.4
249
+ signing_key:
250
+ specification_version: 4
251
+ summary: A skeleton that allows extracting queries into atomic, reusable classes.
252
+ test_files:
253
+ - test/db/models.rb
254
+ - test/db/schema.rb
255
+ - test/inquery/query/chainable_test.rb
256
+ - test/inquery/query_test.rb
257
+ - test/queries/group/fetch_as_json.rb
258
+ - test/queries/group/fetch_green.rb
259
+ - test/queries/group/fetch_red.rb
260
+ - test/queries/group/filter_with_color.rb
261
+ - test/queries/user/fetch_all.rb
262
+ - test/queries/user/fetch_in_group.rb
263
+ - test/queries/user/fetch_in_group_rel.rb
264
+ - test/test_helper.rb
265
+ has_rdoc: