parascope 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/lib/parascope/query.rb +6 -2
- data/lib/parascope/query/api_methods.rb +1 -0
- data/lib/parascope/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6caa45deb0d23160ab7595714e4517eed4306e10
|
4
|
+
data.tar.gz: e407dc5cb9e132c3c814ce43ad94ea64a1c57fb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af3bf60ea924a9b8326f962424f08ce71b0623fdc5c6277109e0eee70077ccd368ca1b2193a2a5410dda1fc2f619232fcbd8039f18caee79c2e60d1effc3126
|
7
|
+
data.tar.gz: baedb425a6571abd713856e34bd3859a75d4c38a2146ccaa96efc56ca9b56924f9c70f13bfb7c713cdaba3848132852c613f5f316d47d33e19988e2c64219904
|
data/README.md
CHANGED
@@ -136,6 +136,8 @@ end
|
|
136
136
|
top-level base scope is yielded to the method block. Note that `base_scope` will
|
137
137
|
not be called if query is initialized with a given scope.
|
138
138
|
|
139
|
+
*Alias:* `base_dataset`
|
140
|
+
|
139
141
|
*Examples:*
|
140
142
|
|
141
143
|
```ruby
|
@@ -180,8 +182,7 @@ end
|
|
180
182
|
- `build(scope: nil, **attributes)` initializes a query with empty params. Handy when
|
181
183
|
query depends only passed attributes and internal logic. Also useful in specs.
|
182
184
|
|
183
|
-
|
184
|
-
|
185
|
+
*Examples:*
|
185
186
|
|
186
187
|
```ruby
|
187
188
|
query = UsersQuery.build(scope: users_scope)
|
@@ -190,9 +191,10 @@ query = UsersQuery.build(scope: users_scope)
|
|
190
191
|
|
191
192
|
#### Instance Methods
|
192
193
|
|
193
|
-
- `initialize(params, scope: nil, **attributes)` initializes a query with
|
194
|
-
an optional scope
|
195
|
-
|
194
|
+
- `initialize(params, scope: nil, dataset: nil, **attributes)` initializes a query with
|
195
|
+
`params`, an optional scope can be passed as `:scope` or `:dataset` option. If passed,
|
196
|
+
it will be used instead of `base_scope`. All additionally passed options are accessible
|
197
|
+
via reader methods in query blocks and elsewhere.
|
196
198
|
|
197
199
|
*Examples:*
|
198
200
|
|
@@ -207,6 +209,8 @@ query = UsersQuery.new(query_params, company: company)
|
|
207
209
|
to base scope. Primary usage is to call this method in `query_by` blocks and return
|
208
210
|
it's mutated version corresponding to passed `query_by` arguments.
|
209
211
|
|
212
|
+
*Alias:* `dataset`
|
213
|
+
|
210
214
|
- `guard(&block)` executes a passed `block`. If this execution returns falsy value,
|
211
215
|
`GuardViolationError` is raised. You can use this method to ensure safety of param
|
212
216
|
values interpolation to a SQL string in a `query_by` block for example.
|
@@ -231,6 +235,8 @@ end
|
|
231
235
|
`resolved_scope(with_projects: true)`). It's the main `Query` instance method that
|
232
236
|
returns the sole purpose of it's instances.
|
233
237
|
|
238
|
+
*Aliases:* `resolved_dataset`, `resolve`
|
239
|
+
|
234
240
|
*Examples:*
|
235
241
|
|
236
242
|
```ruby
|
data/lib/parascope/query.rb
CHANGED
@@ -21,9 +21,9 @@ module Parascope
|
|
21
21
|
new({}, **attrs)
|
22
22
|
end
|
23
23
|
|
24
|
-
def initialize(params, scope: nil, **attrs)
|
24
|
+
def initialize(params, scope: nil, dataset: nil, **attrs)
|
25
25
|
@params = Hashie::Mash.new(klass.defaults).merge(params || {})
|
26
|
-
@scope = scope unless scope.nil?
|
26
|
+
@scope = scope || dataset unless scope.nil? && dataset.nil?
|
27
27
|
@attrs = attrs.freeze
|
28
28
|
@base_params = @params
|
29
29
|
define_attr_readers
|
@@ -32,6 +32,7 @@ module Parascope
|
|
32
32
|
def scope
|
33
33
|
@scope ||= base_scope
|
34
34
|
end
|
35
|
+
alias_method :dataset, :scope
|
35
36
|
|
36
37
|
def base_scope
|
37
38
|
scope = klass.ancestors
|
@@ -47,6 +48,7 @@ module Parascope
|
|
47
48
|
|
48
49
|
scope
|
49
50
|
end
|
51
|
+
alias_method :base_dataset, :base_scope
|
50
52
|
|
51
53
|
def resolved_scope(*args)
|
52
54
|
arg_params = args.pop if args.last.is_a?(Hash)
|
@@ -54,6 +56,8 @@ module Parascope
|
|
54
56
|
|
55
57
|
clone_with_params(trues(args).merge(arg_params || {})).resolved_scope
|
56
58
|
end
|
59
|
+
alias_method :resolved_dataset, :resolved_scope
|
60
|
+
alias_method :resolve, :resolved_scope
|
57
61
|
|
58
62
|
def klass
|
59
63
|
sifted? ? singleton_class : self.class
|
data/lib/parascope/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parascope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Kuzko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.4.8
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Builds a params-sifted scope
|