paraphrase 0.13.0 → 0.13.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
  SHA256:
3
- metadata.gz: 43ecedf4659ea90875e14caa3f42c0a4c038dfdd7f3b52521fd60219275a779c
4
- data.tar.gz: daa305cc3762548d156e03b988efa086793c1b74dabd9201ceb205042c904a10
3
+ metadata.gz: 3e88857c04d639004cb135da22ea4c6633b94b810a7f3a5d32a118d41d1702a9
4
+ data.tar.gz: 6374a8407974747997ce431d12ef6aa9aedd672e6f800c2d1a314d4f2edfdd47
5
5
  SHA512:
6
- metadata.gz: e74d5856ec1dea6a7b31684008302ba1e873633083a376a2b161054347ac6fdb83b0838b90fe5cdaee38a67d8ad6fee07cdef0a45d763fa51b19b9dfcd87bdaa
7
- data.tar.gz: 57787b886775a26c1afe0f8784fed1dc223a6f33b6b89c485e446936d30f75cf4813d786a074f7c68c25990554aed146a5cdbd1eda261a30100bf3077709d441
6
+ metadata.gz: 4f8d982b5b0af890c2f61fb9d7811ba017d85311b6204581a6dad9ed63331eaf2853c12e2afee9dd7615cb689c258a104e320d1497998062a413b8e435a536a9
7
+ data.tar.gz: 1445af920f0ddaa4c90ea42889dec9e17d850db3bd000eafb5dbcfb5b589a9fe83220b09b50b9948128d2cb46d76d659130c2e4c8b49fd535c1bf408b712944d
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ doc/
4
4
  vendor/cache/*.gem
5
5
  .yardoc
6
6
  coverage
7
+ .byebug_history
data/.travis.yml CHANGED
@@ -13,6 +13,3 @@ before_install:
13
13
  - gem update --system
14
14
  - gem install bundler
15
15
  script: 'bundle exec rake'
16
- matrix:
17
- allow_failures:
18
- - gemfile: gemfiles/5.2.gemfile
data/Appraisals CHANGED
@@ -14,7 +14,7 @@ appraise '5.1' do
14
14
  end
15
15
 
16
16
  appraise '5.2' do
17
- gem 'activerecord', '~> 5.2.0.rc2'
18
- gem 'activesupport', '~> 5.2.0.rc2'
19
- gem 'actionpack', '~> 5.2.0.rc2'
17
+ gem 'activerecord', '~> 5.2.0'
18
+ gem 'activesupport', '~> 5.2.0'
19
+ gem 'actionpack', '~> 5.2.0'
20
20
  end
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.13.1] - 2018-04-12
6
+ ### Added
7
+ * Add `Query#[]` for easier, validated lookup of `params` values.
8
+ * Support released version of rails 5.2
9
+
10
+ ### Fixed
11
+ * Correctly handle `ActionController::Parameters` in `ParamsFilter` processing.
12
+
5
13
  ## [0.13.0] - 2018-04-09
6
14
  ### Removed
7
15
  * Support for ruby < 2.3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- paraphrase (0.13.0)
4
+ paraphrase (0.13.1)
5
5
  activemodel (>= 4.2, < 6.0)
6
6
  activerecord (>= 4.2, < 6.0)
7
7
  activesupport (>= 4.2, < 6.0)
@@ -40,6 +40,7 @@ GEM
40
40
  thor (>= 0.14.0)
41
41
  arel (6.0.4)
42
42
  builder (3.2.3)
43
+ byebug (10.0.2)
43
44
  coderay (1.1.2)
44
45
  concurrent-ruby (1.0.5)
45
46
  crass (1.0.4)
@@ -100,13 +101,14 @@ DEPENDENCIES
100
101
  activesupport (~> 4.2.0)
101
102
  appraisal (>= 1.0)
102
103
  bundler (~> 1.0)
104
+ byebug (~> 10.0)
103
105
  paraphrase!
104
106
  pry (~> 0.9)
105
107
  rake (~> 12.3)
106
108
  redcarpet (~> 3.2)
107
109
  rspec (~> 3.0)
108
110
  sqlite3 (~> 1.3.6)
109
- yard (~> 0.7)
111
+ yard (~> 0.9)
110
112
 
111
113
  BUNDLED WITH
112
114
  1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- paraphrase (0.13.0)
4
+ paraphrase (0.13.1)
5
5
  activemodel (>= 4.2, < 6.0)
6
6
  activerecord (>= 4.2, < 6.0)
7
7
  activesupport (>= 4.2, < 6.0)
@@ -39,6 +39,7 @@ GEM
39
39
  thor (>= 0.14.0)
40
40
  arel (7.1.4)
41
41
  builder (3.2.3)
42
+ byebug (10.0.2)
42
43
  coderay (1.1.2)
43
44
  concurrent-ruby (1.0.5)
44
45
  crass (1.0.4)
@@ -96,13 +97,14 @@ DEPENDENCIES
96
97
  activesupport (~> 5.0.0)
97
98
  appraisal (>= 1.0)
98
99
  bundler (~> 1.0)
100
+ byebug (~> 10.0)
99
101
  paraphrase!
100
102
  pry (~> 0.9)
101
103
  rake (~> 12.3)
102
104
  redcarpet (~> 3.2)
103
105
  rspec (~> 3.0)
104
106
  sqlite3 (~> 1.3.6)
105
- yard (~> 0.7)
107
+ yard (~> 0.9)
106
108
 
107
109
  BUNDLED WITH
108
110
  1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- paraphrase (0.13.0)
4
+ paraphrase (0.13.1)
5
5
  activemodel (>= 4.2, < 6.0)
6
6
  activerecord (>= 4.2, < 6.0)
7
7
  activesupport (>= 4.2, < 6.0)
@@ -39,6 +39,7 @@ GEM
39
39
  thor (>= 0.14.0)
40
40
  arel (8.0.0)
41
41
  builder (3.2.3)
42
+ byebug (10.0.2)
42
43
  coderay (1.1.2)
43
44
  concurrent-ruby (1.0.5)
44
45
  crass (1.0.4)
@@ -96,13 +97,14 @@ DEPENDENCIES
96
97
  activesupport (~> 5.1.0)
97
98
  appraisal (>= 1.0)
98
99
  bundler (~> 1.0)
100
+ byebug (~> 10.0)
99
101
  paraphrase!
100
102
  pry (~> 0.9)
101
103
  rake (~> 12.3)
102
104
  redcarpet (~> 3.2)
103
105
  rspec (~> 3.0)
104
106
  sqlite3 (~> 1.3.6)
105
- yard (~> 0.7)
107
+ yard (~> 0.9)
106
108
 
107
109
  BUNDLED WITH
108
110
  1.16.1
data/gemfiles/5.2.gemfile CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.2.0.rc2"
6
- gem "activesupport", "~> 5.2.0.rc2"
7
- gem "actionpack", "~> 5.2.0.rc2"
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "activesupport", "~> 5.2.0"
7
+ gem "actionpack", "~> 5.2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- paraphrase (0.13.0)
4
+ paraphrase (0.13.1)
5
5
  activemodel (>= 4.2, < 6.0)
6
6
  activerecord (>= 4.2, < 6.0)
7
7
  activesupport (>= 4.2, < 6.0)
@@ -9,26 +9,26 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (5.2.0.rc2)
13
- actionview (= 5.2.0.rc2)
14
- activesupport (= 5.2.0.rc2)
12
+ actionpack (5.2.0)
13
+ actionview (= 5.2.0)
14
+ activesupport (= 5.2.0)
15
15
  rack (~> 2.0)
16
16
  rack-test (>= 0.6.3)
17
17
  rails-dom-testing (~> 2.0)
18
18
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.2.0.rc2)
20
- activesupport (= 5.2.0.rc2)
19
+ actionview (5.2.0)
20
+ activesupport (= 5.2.0)
21
21
  builder (~> 3.1)
22
22
  erubi (~> 1.4)
23
23
  rails-dom-testing (~> 2.0)
24
24
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
- activemodel (5.2.0.rc2)
26
- activesupport (= 5.2.0.rc2)
27
- activerecord (5.2.0.rc2)
28
- activemodel (= 5.2.0.rc2)
29
- activesupport (= 5.2.0.rc2)
25
+ activemodel (5.2.0)
26
+ activesupport (= 5.2.0)
27
+ activerecord (5.2.0)
28
+ activemodel (= 5.2.0)
29
+ activesupport (= 5.2.0)
30
30
  arel (>= 9.0)
31
- activesupport (5.2.0.rc2)
31
+ activesupport (5.2.0)
32
32
  concurrent-ruby (~> 1.0, >= 1.0.2)
33
33
  i18n (>= 0.7, < 2)
34
34
  minitest (~> 5.1)
@@ -39,6 +39,7 @@ GEM
39
39
  thor (>= 0.14.0)
40
40
  arel (9.0.0)
41
41
  builder (3.2.3)
42
+ byebug (10.0.2)
42
43
  coderay (1.1.2)
43
44
  concurrent-ruby (1.0.5)
44
45
  crass (1.0.4)
@@ -91,18 +92,19 @@ PLATFORMS
91
92
  ruby
92
93
 
93
94
  DEPENDENCIES
94
- actionpack (~> 5.2.0.rc2)
95
- activerecord (~> 5.2.0.rc2)
96
- activesupport (~> 5.2.0.rc2)
95
+ actionpack (~> 5.2.0)
96
+ activerecord (~> 5.2.0)
97
+ activesupport (~> 5.2.0)
97
98
  appraisal (>= 1.0)
98
99
  bundler (~> 1.0)
100
+ byebug (~> 10.0)
99
101
  paraphrase!
100
102
  pry (~> 0.9)
101
103
  rake (~> 12.3)
102
104
  redcarpet (~> 3.2)
103
105
  rspec (~> 3.0)
104
106
  sqlite3 (~> 1.3.6)
105
- yard (~> 0.7)
107
+ yard (~> 0.9)
106
108
 
107
109
  BUNDLED WITH
108
110
  1.16.1
data/lib/paraphrase.rb CHANGED
@@ -1,13 +1,31 @@
1
1
  module Paraphrase
2
2
  class DuplicateMappingError < StandardError
3
3
  def initialize(scope_name)
4
- @message = "scope :#{scope_name} has already been mapped"
4
+ @scope_name = scope_name
5
+ end
6
+
7
+ def message
8
+ "scope :#{@scope_name} has already been mapped"
5
9
  end
6
10
  end
7
11
 
8
12
  class NoQueryDefined < StandardError
9
13
  def initialize(query_name)
10
- @message = "No query class found. #{query_name} must be defined as a subclass of `Paraphrase::Query`"
14
+ @query_name = query_name
15
+ end
16
+
17
+ def message
18
+ "No query class found. #{@query_name} must be defined as a subclass of `Paraphrase::Query`"
19
+ end
20
+ end
21
+
22
+ class UndefinedKeyError < StandardError
23
+ def initialize(invalid_key, keys)
24
+ @invalid_key, @keys = invalid_key, keys
25
+ end
26
+
27
+ def message
28
+ "key `#{@invalid_key}' is not a valid key for this query; valid keys are: #{@keys.join(', ')}"
11
29
  end
12
30
  end
13
31
  end
@@ -17,14 +17,14 @@ module Paraphrase
17
17
  # can be re-opened inside the {Query} class definition or by calling the
18
18
  # {Query.param param} class method.
19
19
  class ParamsFilter
20
- attr_reader :params, :result
21
-
22
- def initialize(unfiltered_params, keys)
23
- @params = unfiltered_params.with_indifferent_access.slice(*keys)
20
+ def initialize(params, keys)
21
+ @keys = keys
22
+ @params = params
23
+ end
24
24
 
25
- @result = keys.inject(HashWithIndifferentAccess.new) do |result, key|
26
- value = respond_to?(key) ? send(key) : @params[key]
27
- value = scrub(value)
25
+ def result
26
+ @keys.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result, key|
27
+ value = scrub(public_send(key))
28
28
 
29
29
  if value.present?
30
30
  result[key] = value
@@ -34,6 +34,14 @@ module Paraphrase
34
34
  end
35
35
  end
36
36
 
37
+ def [](key)
38
+ @params[key.to_sym] || @params[key.to_s]
39
+ end
40
+
41
+ def params
42
+ self
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def scrub(value)
@@ -3,7 +3,6 @@ require 'active_support/core_ext/class/attribute'
3
3
  require 'active_support/core_ext/module/delegation'
4
4
  require 'active_support/core_ext/string/inflections'
5
5
  require 'active_support/core_ext/array/extract_options'
6
- require 'active_support/hash_with_indifferent_access'
7
6
 
8
7
  require 'paraphrase/active_model'
9
8
  require 'paraphrase/mapping'
@@ -68,6 +67,10 @@ module Paraphrase
68
67
 
69
68
  keys.each do |key|
70
69
  define_method(key) { params[key] }
70
+
71
+ params_filter.class_eval do
72
+ define_method(key) { params[key] }
73
+ end
71
74
  end
72
75
  end
73
76
 
@@ -105,6 +108,17 @@ module Paraphrase
105
108
  end
106
109
  end
107
110
 
111
+ # Look up a `params` value
112
+ #
113
+ # @param [String,Symbol] key key to read
114
+ def [](key)
115
+ unless keys.include?(key.to_sym)
116
+ raise UndefinedKeyError.new(key, keys)
117
+ end
118
+
119
+ params[key]
120
+ end
121
+
108
122
  # Return an `ActiveRecord::Relation` corresponding to the source class
109
123
  # determined from the `source` class attribute that defaults to the name of
110
124
  # the class.
@@ -1,3 +1,3 @@
1
1
  module Paraphrase
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
data/paraphrase.gemspec CHANGED
@@ -30,7 +30,8 @@ Gem::Specification.new do |gem|
30
30
 
31
31
  gem.add_development_dependency 'actionpack', '>= 4.2', '< 6.0'
32
32
  gem.add_development_dependency 'bundler', '~> 1.0'
33
- gem.add_development_dependency 'yard', '~> 0.7'
33
+ gem.add_development_dependency "byebug", "~> 10.0"
34
+ gem.add_development_dependency 'yard', '~> 0.9'
34
35
  gem.add_development_dependency 'rspec', '~> 3.0'
35
36
  gem.add_development_dependency "rake", "~> 12.3"
36
37
  gem.add_development_dependency "appraisal", ">= 1.0"
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'action_view/test_case'
3
+ require "action_controller/metal/strong_parameters"
3
4
 
4
5
  module Paraphrase
5
6
  describe Query do
@@ -155,6 +156,29 @@ module Paraphrase
155
156
  expect(result).not_to include green_post
156
157
  end
157
158
 
159
+ it "works with ActionController::Parameters" do
160
+ query = PostQuery.new(ActionController::Parameters.new(title: "D3 How-To"))
161
+
162
+ expect(query.params).to have_key "title"
163
+ end
164
+
165
+ it "handles symbol or string keys when filtering params" do
166
+ query = PostQuery.new(title: "Top 10", "authors" => "Andre")
167
+
168
+ expect(query.params[:title]).to eq "Top 10"
169
+ expect(query.params[:authors]).to eq "Andre"
170
+ end
171
+
172
+ describe "#[]" do
173
+ it "raises if argument is not in set of defined keys" do
174
+ query = PostQuery.new(title: "Another How-To", authors: ["jim"])
175
+
176
+ expect(query["authors"]).to eq ["jim"]
177
+ expect(query[:title]).to eq "Another How-To"
178
+ expect { query["sorted_by"] }.to raise_error Paraphrase::UndefinedKeyError
179
+ end
180
+ end
181
+
158
182
  describe 'is action view compliant' do
159
183
  it 'by working with form builders' do
160
184
  router = ActionDispatch::Routing::RouteSet.new
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,6 @@
1
- if ENV.key?('CODECLIMATE_REPO_TOKEN')
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
- end
5
-
6
1
  require 'rspec'
7
2
  require 'pry'
3
+ require "byebug"
8
4
  require 'paraphrase'
9
5
  require 'active_record'
10
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraphrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Gutierrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-09 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -104,20 +104,34 @@ dependencies:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '1.0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: byebug
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '10.0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '10.0'
107
121
  - !ruby/object:Gem::Dependency
108
122
  name: yard
109
123
  requirement: !ruby/object:Gem::Requirement
110
124
  requirements:
111
125
  - - "~>"
112
126
  - !ruby/object:Gem::Version
113
- version: '0.7'
127
+ version: '0.9'
114
128
  type: :development
115
129
  prerelease: false
116
130
  version_requirements: !ruby/object:Gem::Requirement
117
131
  requirements:
118
132
  - - "~>"
119
133
  - !ruby/object:Gem::Version
120
- version: '0.7'
134
+ version: '0.9'
121
135
  - !ruby/object:Gem::Dependency
122
136
  name: rspec
123
137
  requirement: !ruby/object:Gem::Requirement