parascope 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc98be2a5b2713d248126d205faadbc007153c7a
4
- data.tar.gz: 8f0dadd459a841defd277566b14740f9d7c7dc52
3
+ metadata.gz: 3195e544c77f3024607110d86b36783250643f85
4
+ data.tar.gz: 22d0aaf9e030c782dd1cd5bcae862dc59642918c
5
5
  SHA512:
6
- metadata.gz: 02fe0357a9573f7e6d9f9e02506d6c30d50c724050a5786c20ddf5981a8a304cf19a9e7b8c971998977cf97a4ee5e3f2bf33b1173cdfe42513c7024f6d8e2482
7
- data.tar.gz: 630a5784a2c1e339945639a45e8a3cdf03e4749c5714f725a8e126788f1ec0c84064c68e79b9e2535fbb6108afd5b91e3fea50fcf33fdf1ad39abc5479bbc2b8
6
+ metadata.gz: 7a95450b4483a64760710e5bd5bfcec52730b7c5b523097080a94a41ad33dcd4dd2c2bda9673294c91cf9139ad2012de9710d01d9118c3a0dae72eff3d3465a1
7
+ data.tar.gz: fd83e9f6f76a1e8396621621898cac2ab10f1adeed9f2a352d97afe7f10014b1cdae1512df9faa9df25e66871582fc84a5a7c23e1bc1d008b2b7ed3f53acd6e0
@@ -0,0 +1,11 @@
1
+ === master
2
+
3
+ === 1.0.1
4
+
5
+ Fix base scope application on sifted instance
6
+
7
+ Add [github release] badge to README
8
+
9
+ Update README, add CHANGELOG
10
+
11
+ === 1.0.0
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Parascope
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/akuzko/parascope.png)](http://travis-ci.org/akuzko/parascope)
4
-
5
3
  Param-based scope generation.
6
4
 
5
+ [![build status](https://secure.travis-ci.org/akuzko/parascope.png)](http://travis-ci.org/akuzko/parascope)
6
+ [![github release](https://img.shields.io/github/release/akuzko/parascope.svg)](https://github.com/akuzko/parascope/releases)
7
+
7
8
  --
8
9
 
9
10
  This gem provides a `Parascope::Query` class with a declarative and convenient API
@@ -71,7 +72,9 @@ query_by(only_active: 'true') { scope.active }
71
72
 
72
73
  # executes block only when *both* params[:first_name] and params[:last_name]
73
74
  # are present:
74
- query_by(:first_name, :last_name) { |first_name, last_name| /* ... */ }
75
+ query_by(:first_name, :last_name) do |first_name, last_name|
76
+ scope.where(first_name: first_name, last_name: last_name)
77
+ end
75
78
 
76
79
  # if query block returns nil, scope will remain intact:
77
80
  query { scope.active if only_active? }
@@ -163,21 +166,27 @@ sift_by(:sort_col, :sort_dir) do |scol, sdir|
163
166
  end
164
167
  ```
165
168
 
169
+ - `build(scope: nil, **attributes)` initializes a query with empty params. Handy when
170
+ query depends only passed attributes and internal logic. Also useful in specs.
171
+
172
+ *Examples:*
173
+
174
+
175
+ ```ruby
176
+ query = UsersQuery.build(scope: users_scope)
177
+ # the same as UsersQuery.new({}, scope: users_scope)
178
+ ```
179
+
166
180
  #### Instance Methods
167
181
 
168
182
  - `initialize(params, scope: nil, **attributes)` initializes a query with `params`,
169
183
  an optional scope (that if passed, is used instead of `base_scope`). All additionally
170
184
  passed options are accessible via reader methods in query blocks and elsewhere.
171
185
 
172
- - `build(scope: nil, **attributes)` initializes a query with empty params. Handy when
173
- query depends only passed attributes and internal logic. Also useful in specs.
174
-
175
186
  *Examples:*
176
187
 
177
188
  ```ruby
178
189
  query = UsersQuery.new(query_params, company: company)
179
-
180
- query = UsersQuery.build(scope: users_scope)
181
190
  ```
182
191
 
183
192
  - `params` returns a parameters passed in initialization. Is a `Hashie::Mash` instance,
@@ -221,7 +230,7 @@ base_scope { company.users }
221
230
  query_by(:only_active) { scope.active }
222
231
 
223
232
  sifter :with_departments do
224
- scope.joins(:departments)
233
+ base_scope { scope.joins(:departments) }
225
234
 
226
235
  query_by(:department_name) { |name| scope.where(departments: {name: name}) }
227
236
  end
@@ -96,6 +96,9 @@ module Parascope
96
96
  singleton_class.instance_exec(*block.values_for(params), &block.block)
97
97
  end
98
98
  params.replace(singleton_class.defaults.merge(params))
99
+ if instance_variable_defined?('@scope') && !singleton_class.base_scope.nil?
100
+ @scope = instance_exec(@scope, &singleton_class.base_scope)
101
+ end
99
102
  @sifted = true
100
103
  end
101
104
 
@@ -1,3 +1,3 @@
1
1
  module Parascope
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Kuzko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -107,6 +107,7 @@ files:
107
107
  - ".gitignore"
108
108
  - ".rspec"
109
109
  - ".travis.yml"
110
+ - CHANGELOG
110
111
  - Gemfile
111
112
  - LICENSE.txt
112
113
  - README.md