paraphrase 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54d269a79cf5f4ab55d4afe39c4f9e0c4dd6841f
4
- data.tar.gz: e95b97c71c317d9e6f534bb7dcfb10037cde2bfe
3
+ metadata.gz: 7eee455eab9622de9d86136dfe8d1b5b766373e1
4
+ data.tar.gz: fbba2474e3febdd44f4937347cdf14888de70125
5
5
  SHA512:
6
- metadata.gz: f69b9ef6eb394171092763aa92144d0f044e0f7668c374a4d609da84d0a2e163d39fa2679771fa9a32894150a8a478002d531acd6f3ff139c521742fa5494b75
7
- data.tar.gz: 93221d4cd686cd4f7a84d958df0608264a4869045ce891239e4dc47d7330c68c2712faf6a049fde322cd3f79fd938e709caf0bea14a96e45822a395ca6d35ce4
6
+ metadata.gz: 146a851d81c039939c2ba35688aaf55e01bc85bf2d3608a1d5441668aee600e37d46cc03aa8eb51b672e77de9fe1704829b239b3e3dd4f44222a3ad1cfc35711
7
+ data.tar.gz: d383c9f1d43cd46e979618feb616c34dcc1acd58fdb70b51c9438cf313aef93540f132422712b6f8f6e2ac240dbe259bb9cf65235cb02cb0c7c248beac681e5f
data/.travis.yml CHANGED
@@ -3,8 +3,8 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1.1
5
5
  - jruby-19mode
6
+ - rbx-2
6
7
  gemfile:
7
- - gemfiles/3.0.gemfile
8
8
  - gemfiles/3.1.gemfile
9
9
  - gemfiles/3.2.gemfile
10
10
  - gemfiles/4.0.gemfile
@@ -15,3 +15,6 @@ env:
15
15
  global:
16
16
  # Code Climate coverage reporting
17
17
  - secure: "VylP1haJogwCq04GRrM3hVfNT4YJiZ4RJoklOQLgqPMRalOCzVPOIRoTz3qpVbdQHf3l18VhVDrDbu2W2qfBKJq7/anIuYYgPd0uRAGliZD4h5B2PgQDqvPeTEftj/g3IYDh6PvZCuhgnxMdldmSnxd9WAjAnkLtjoiLgE6elCE="
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: rbx-2
data/Appraisals CHANGED
@@ -1,29 +1,23 @@
1
- appraise '3.0' do
2
- gem 'activerecord', '~> 3.0'
3
- gem 'activesupport', '~> 3.0'
4
- gem 'actionpack', '~> 3.0'
5
- end
6
-
7
1
  appraise '3.1' do
8
- gem 'activerecord', '~> 3.1'
9
- gem 'activesupport', '~> 3.1'
10
- gem 'actionpack', '~> 3.1'
2
+ gem 'activerecord', '~> 3.1.0'
3
+ gem 'activesupport', '~> 3.1.0'
4
+ gem 'actionpack', '~> 3.1.0'
11
5
  end
12
6
 
13
7
  appraise '3.2' do
14
- gem 'activerecord', '~> 3.2'
15
- gem 'activesupport', '~> 3.2'
16
- gem 'actionpack', '~> 3.2'
8
+ gem 'activerecord', '~> 3.2.0'
9
+ gem 'activesupport', '~> 3.2.0'
10
+ gem 'actionpack', '~> 3.2.0'
17
11
  end
18
12
 
19
13
  appraise '4.0' do
20
- gem 'activerecord', '~> 4.0'
21
- gem 'activesupport', '~> 4.0'
22
- gem 'actionpack', '~> 4.0'
14
+ gem 'activerecord', '~> 4.0.0'
15
+ gem 'activesupport', '~> 4.0.0'
16
+ gem 'actionpack', '~> 4.0.0'
23
17
  end
24
18
 
25
19
  appraise '4.1' do
26
- gem 'activerecord', '~> 4.1'
27
- gem 'activesupport', '~> 4.1'
28
- gem 'actionpack', '~> 4.1'
20
+ gem 'activerecord', '~> 4.1.0'
21
+ gem 'activesupport', '~> 4.1.0'
22
+ gem 'actionpack', '~> 4.1.0'
29
23
  end
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- ## 0.9.0
1
+ ## Next Release
2
+
3
+ * Add convenience class-level API for pre-processing query params
4
+ * Pre-process params and then scrub them from
5
+ * Rename `Scope` to the more appropriate `Mapping`
6
+ * Mark `Mapping` and `ActiveModel` classes as private API
7
+ * Add ability to define scopes in the `Query` subclass via `Paraphrase::Repository`
8
+ (see README)
9
+ * Refactor `Query.source` to be a regular class attribute
10
+ * Require `Paraphrase::Query` be initialized with an `ActiveRecord::Relation`
11
+ instance. Ensure this happens in `Paraphrase::Syntax`.
12
+
13
+ ## 0.9.0 / 5-2-2014
2
14
 
3
15
  * Define methods to process query params on a subclass of `Paraphrase::Params`
4
16
  that also handles filtering blank query params.
data/README.md CHANGED
@@ -42,7 +42,7 @@ symbol to the `source` method.
42
42
  # app/queries/admin_post_query.rb
43
43
  class AdminPostQuery < Paraphrase::Query
44
44
  # This needs the source specific since it will look for an `AdminPost` model.
45
- source :Post
45
+ self.source = :Post
46
46
  end
47
47
  ```
48
48
 
@@ -196,23 +196,26 @@ Post.paraphrase(published: '1').to_sql
196
196
 
197
197
  ### Pre-processing Query Params
198
198
 
199
- By default, for each query param specified that maps to a model scope, a method
200
- is defined on the query class that fetches the value for that key. To pre-process a
201
- query param, such as an ISO formatted date, override the method in the query
202
- class.
199
+ To pre-process a query param, such as an ISO formatted date, you can either use
200
+ the `param` class method or re-open the `ParamsFilter` class that is defined
201
+ when inheriting from `Paraphrase::Query`. Using the `param` class method
202
+ defines the equivalent method on the `ParamsFilter` class.
203
+
204
+ In the method, you have access to the `params` attribute that represents the
205
+ original, unprocessed params.
203
206
 
204
207
  ```ruby
205
208
  class PostQuery < Paraphrase::Query
206
209
  map :start_date, :end_date, to: :published_within
207
210
 
208
- class Params < Paraphrase::Params
211
+ class ParamsFilter
209
212
  def start_date
210
- @start_date ||= Time.zone.parse(params[:start_date]) rescue nil
213
+ Time.zone.parse(params[:start_date]) rescue nil
211
214
  end
215
+ end
212
216
 
213
- def end_date
214
- @start_date ||= Time.zone.parse(params[:end_date]) rescue nil
215
- end
217
+ param :end_date do
218
+ Time.zone.parse(params[:end_date]) rescue nil
216
219
  end
217
220
  end
218
221
 
@@ -230,9 +233,48 @@ In the above example, if either `:start_date` or `:end_date` are incorrectly
230
233
  formatted, the `pubished_within` scope will not be applied because the values
231
234
  are will be `nil`.
232
235
 
236
+ ### Define scopes on the `Query` class
237
+
238
+ If your model is cluttered with scopes that aren't general-purpose, and only
239
+ used by your query class, you can define them in the query class. You can
240
+ define scopes by re-opening the `Repository` class defined on inheritance from
241
+ `Paraphrase::Query`. There is also the `scope` class method that serves as a
242
+ proxy for defining methods on the `Repository` class.
243
+
244
+ In the method, you have to call the scope on the `relation` property of the
245
+ `Repository` instance.
246
+
247
+ ```ruby
248
+ class PostQuery < Paraphrase::Query
249
+ map :title, to: :titled
250
+ map :authors, to: :by_users
251
+ map :is_published, to: :published
252
+
253
+ scope :by_users do |authors|
254
+ relation.joins(:user).where(users: { name: authors })
255
+ end
256
+
257
+ # OR
258
+ # class Repository
259
+ # def by_users(authors)
260
+ # relation.joins(:user).where(users: { name: authors })
261
+ # end
262
+ # end
263
+ end
264
+
265
+ class Post < ActiveRecord::Base
266
+ end
267
+
268
+ Post.paraphrase(authors: ['Robert', 'Susie']).to_sql
269
+ # => SELECT "posts".* FROM "posts"
270
+ # INNER JOIN "users" ON "users"."id" = "posts"."user_id"
271
+ # WHERE "users"."name" IN ('Robert', 'Susie')
272
+ ```
273
+
233
274
  ### Using with `FormBuilder`
234
275
 
235
- The `Paraphrase::Query` class implements the `ActiveModel` API required for use with form builders.
276
+ The `Paraphrase::Query` class implements the `ActiveModel` API required for use
277
+ with form builders.
236
278
 
237
279
  ```ruby
238
280
  class PostQuery < Paraphrase::Query
data/gemfiles/3.1.gemfile CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.1"
6
- gem "activesupport", "~> 3.1"
7
- gem "actionpack", "~> 3.1"
5
+ gem "activerecord", "~> 3.1.0"
6
+ gem "activesupport", "~> 3.1.0"
7
+ gem "actionpack", "~> 3.1.0"
8
8
 
9
9
  gemspec :path=>"../"
@@ -1,39 +1,40 @@
1
1
  PATH
2
- remote: /Users/edd_d/Work/paraphrase
2
+ remote: ../
3
3
  specs:
4
- paraphrase (0.9.0)
5
- activemodel (>= 3.0, < 4.2)
6
- activerecord (>= 3.0, < 4.2)
7
- activesupport (>= 3.0, < 4.2)
4
+ paraphrase (0.10.0)
5
+ activemodel (>= 3.1, < 4.2)
6
+ activerecord (>= 3.1, < 4.2)
7
+ activesupport (>= 3.1, < 4.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (3.2.16)
13
- activemodel (= 3.2.16)
14
- activesupport (= 3.2.16)
12
+ actionpack (3.1.12)
13
+ activemodel (= 3.1.12)
14
+ activesupport (= 3.1.12)
15
15
  builder (~> 3.0.0)
16
16
  erubis (~> 2.7.0)
17
- journey (~> 1.0.4)
18
- rack (~> 1.4.5)
17
+ i18n (~> 0.6)
18
+ rack (~> 1.3.6)
19
19
  rack-cache (~> 1.2)
20
+ rack-mount (~> 0.8.2)
20
21
  rack-test (~> 0.6.1)
21
- sprockets (~> 2.2.1)
22
- activemodel (3.2.16)
23
- activesupport (= 3.2.16)
22
+ sprockets (~> 2.0.4)
23
+ activemodel (3.1.12)
24
+ activesupport (= 3.1.12)
24
25
  builder (~> 3.0.0)
25
- activerecord (3.2.16)
26
- activemodel (= 3.2.16)
27
- activesupport (= 3.2.16)
28
- arel (~> 3.0.2)
26
+ i18n (~> 0.6)
27
+ activerecord (3.1.12)
28
+ activemodel (= 3.1.12)
29
+ activesupport (= 3.1.12)
30
+ arel (~> 2.2.3)
29
31
  tzinfo (~> 0.3.29)
30
- activesupport (3.2.16)
31
- i18n (~> 0.6, >= 0.6.4)
32
+ activesupport (3.1.12)
32
33
  multi_json (~> 1.0)
33
34
  appraisal (0.5.2)
34
35
  bundler
35
36
  rake
36
- arel (3.0.3)
37
+ arel (2.2.3)
37
38
  builder (3.0.4)
38
39
  codeclimate-test-reporter (0.3.0)
39
40
  simplecov (>= 0.7.1, < 1.0.0)
@@ -43,51 +44,55 @@ GEM
43
44
  erubis (2.7.0)
44
45
  hike (1.2.3)
45
46
  i18n (0.6.9)
46
- journey (1.0.4)
47
47
  method_source (0.8.2)
48
- multi_json (1.8.4)
49
- pry (0.9.12.4)
48
+ multi_json (1.10.1)
49
+ pry (0.9.12.6)
50
50
  coderay (~> 1.0)
51
51
  method_source (~> 0.8)
52
52
  slop (~> 3.4)
53
- rack (1.4.5)
53
+ rack (1.3.10)
54
54
  rack-cache (1.2)
55
55
  rack (>= 0.4)
56
+ rack-mount (0.8.3)
57
+ rack (>= 1.0.0)
56
58
  rack-test (0.6.2)
57
59
  rack (>= 1.0)
58
60
  rake (0.9.6)
59
61
  redcarpet (2.1.1)
60
- rspec (2.14.1)
61
- rspec-core (~> 2.14.0)
62
- rspec-expectations (~> 2.14.0)
63
- rspec-mocks (~> 2.14.0)
64
- rspec-core (2.14.7)
65
- rspec-expectations (2.14.4)
66
- diff-lcs (>= 1.1.3, < 2.0)
67
- rspec-mocks (2.14.4)
62
+ rspec (3.0.0)
63
+ rspec-core (~> 3.0.0)
64
+ rspec-expectations (~> 3.0.0)
65
+ rspec-mocks (~> 3.0.0)
66
+ rspec-core (3.0.0)
67
+ rspec-support (~> 3.0.0)
68
+ rspec-expectations (3.0.0)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.0.0)
71
+ rspec-mocks (3.0.0)
72
+ rspec-support (~> 3.0.0)
73
+ rspec-support (3.0.0)
68
74
  simplecov (0.8.2)
69
75
  docile (~> 1.1.0)
70
76
  multi_json
71
77
  simplecov-html (~> 0.8.0)
72
78
  simplecov-html (0.8.0)
73
- slop (3.4.7)
74
- sprockets (2.2.2)
79
+ slop (3.5.0)
80
+ sprockets (2.0.4)
75
81
  hike (~> 1.2)
76
- multi_json (~> 1.0)
77
82
  rack (~> 1.0)
78
83
  tilt (~> 1.1, != 1.3.0)
79
- sqlite3 (1.3.8)
84
+ sqlite3 (1.3.9)
80
85
  tilt (1.4.1)
81
- tzinfo (0.3.38)
82
- yard (0.8.7.3)
86
+ tzinfo (0.3.39)
87
+ yard (0.8.7.4)
83
88
 
84
89
  PLATFORMS
85
90
  ruby
86
91
 
87
92
  DEPENDENCIES
88
- actionpack (~> 3.1)
89
- activerecord (~> 3.1)
90
- activesupport (~> 3.1)
93
+ actionpack (~> 3.1.0)
94
+ activerecord (~> 3.1.0)
95
+ activesupport (~> 3.1.0)
91
96
  appraisal (~> 0.4)
92
97
  bundler (~> 1.0)
93
98
  codeclimate-test-reporter (~> 0.3)
@@ -95,6 +100,6 @@ DEPENDENCIES
95
100
  pry (~> 0.9)
96
101
  rake (~> 0.9.2)
97
102
  redcarpet (~> 2.1.1)
98
- rspec (~> 2.14)
103
+ rspec (~> 3.0)
99
104
  sqlite3 (~> 1.3.6)
100
105
  yard (~> 0.7)
data/gemfiles/3.2.gemfile CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2"
6
- gem "activesupport", "~> 3.2"
7
- gem "actionpack", "~> 3.2"
5
+ gem "activerecord", "~> 3.2.0"
6
+ gem "activesupport", "~> 3.2.0"
7
+ gem "actionpack", "~> 3.2.0"
8
8
 
9
9
  gemspec :path=>"../"
@@ -1,17 +1,17 @@
1
1
  PATH
2
- remote: /Users/edd_d/Work/paraphrase
2
+ remote: ../
3
3
  specs:
4
- paraphrase (0.9.0)
5
- activemodel (>= 3.0, < 4.2)
6
- activerecord (>= 3.0, < 4.2)
7
- activesupport (>= 3.0, < 4.2)
4
+ paraphrase (0.10.0)
5
+ activemodel (>= 3.1, < 4.2)
6
+ activerecord (>= 3.1, < 4.2)
7
+ activesupport (>= 3.1, < 4.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (3.2.16)
13
- activemodel (= 3.2.16)
14
- activesupport (= 3.2.16)
12
+ actionpack (3.2.18)
13
+ activemodel (= 3.2.18)
14
+ activesupport (= 3.2.18)
15
15
  builder (~> 3.0.0)
16
16
  erubis (~> 2.7.0)
17
17
  journey (~> 1.0.4)
@@ -19,15 +19,15 @@ GEM
19
19
  rack-cache (~> 1.2)
20
20
  rack-test (~> 0.6.1)
21
21
  sprockets (~> 2.2.1)
22
- activemodel (3.2.16)
23
- activesupport (= 3.2.16)
22
+ activemodel (3.2.18)
23
+ activesupport (= 3.2.18)
24
24
  builder (~> 3.0.0)
25
- activerecord (3.2.16)
26
- activemodel (= 3.2.16)
27
- activesupport (= 3.2.16)
25
+ activerecord (3.2.18)
26
+ activemodel (= 3.2.18)
27
+ activesupport (= 3.2.18)
28
28
  arel (~> 3.0.2)
29
29
  tzinfo (~> 0.3.29)
30
- activesupport (3.2.16)
30
+ activesupport (3.2.18)
31
31
  i18n (~> 0.6, >= 0.6.4)
32
32
  multi_json (~> 1.0)
33
33
  appraisal (0.5.2)
@@ -45,8 +45,8 @@ GEM
45
45
  i18n (0.6.9)
46
46
  journey (1.0.4)
47
47
  method_source (0.8.2)
48
- multi_json (1.8.4)
49
- pry (0.9.12.4)
48
+ multi_json (1.10.1)
49
+ pry (0.9.12.6)
50
50
  coderay (~> 1.0)
51
51
  method_source (~> 0.8)
52
52
  slop (~> 3.4)
@@ -57,37 +57,41 @@ GEM
57
57
  rack (>= 1.0)
58
58
  rake (0.9.6)
59
59
  redcarpet (2.1.1)
60
- rspec (2.14.1)
61
- rspec-core (~> 2.14.0)
62
- rspec-expectations (~> 2.14.0)
63
- rspec-mocks (~> 2.14.0)
64
- rspec-core (2.14.7)
65
- rspec-expectations (2.14.4)
66
- diff-lcs (>= 1.1.3, < 2.0)
67
- rspec-mocks (2.14.4)
60
+ rspec (3.0.0)
61
+ rspec-core (~> 3.0.0)
62
+ rspec-expectations (~> 3.0.0)
63
+ rspec-mocks (~> 3.0.0)
64
+ rspec-core (3.0.0)
65
+ rspec-support (~> 3.0.0)
66
+ rspec-expectations (3.0.0)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.0.0)
69
+ rspec-mocks (3.0.0)
70
+ rspec-support (~> 3.0.0)
71
+ rspec-support (3.0.0)
68
72
  simplecov (0.8.2)
69
73
  docile (~> 1.1.0)
70
74
  multi_json
71
75
  simplecov-html (~> 0.8.0)
72
76
  simplecov-html (0.8.0)
73
- slop (3.4.7)
77
+ slop (3.5.0)
74
78
  sprockets (2.2.2)
75
79
  hike (~> 1.2)
76
80
  multi_json (~> 1.0)
77
81
  rack (~> 1.0)
78
82
  tilt (~> 1.1, != 1.3.0)
79
- sqlite3 (1.3.8)
83
+ sqlite3 (1.3.9)
80
84
  tilt (1.4.1)
81
- tzinfo (0.3.38)
82
- yard (0.8.7.3)
85
+ tzinfo (0.3.39)
86
+ yard (0.8.7.4)
83
87
 
84
88
  PLATFORMS
85
89
  ruby
86
90
 
87
91
  DEPENDENCIES
88
- actionpack (~> 3.2)
89
- activerecord (~> 3.2)
90
- activesupport (~> 3.2)
92
+ actionpack (~> 3.2.0)
93
+ activerecord (~> 3.2.0)
94
+ activesupport (~> 3.2.0)
91
95
  appraisal (~> 0.4)
92
96
  bundler (~> 1.0)
93
97
  codeclimate-test-reporter (~> 0.3)
@@ -95,6 +99,6 @@ DEPENDENCIES
95
99
  pry (~> 0.9)
96
100
  rake (~> 0.9.2)
97
101
  redcarpet (~> 2.1.1)
98
- rspec (~> 2.14)
102
+ rspec (~> 3.0)
99
103
  sqlite3 (~> 1.3.6)
100
104
  yard (~> 0.7)