Skip to content

Commit

Permalink
Allow strong parameters support (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Mar 8, 2022
1 parent e700841 commit f7eb9a8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["2.6", "2.7", "3.0"]
ruby-version: ["2.7", "3.0", "3.1"]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ inherit_mode:
- Exclude

AllCops:
TargetRubyVersion: "2.6"
TargetRubyVersion: "2.7"
Naming/FileName:
Exclude: [lib/filterable-by.rb]
87 changes: 39 additions & 48 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
PATH
remote: .
specs:
filterable-by (0.5.2)
filterable-by (0.5.3)
activerecord
activesupport

GEM
remote: http://rubygems.org/
specs:
activemodel (6.1.3.1)
activesupport (= 6.1.3.1)
activerecord (6.1.3.1)
activemodel (= 6.1.3.1)
activesupport (= 6.1.3.1)
activesupport (6.1.3.1)
activemodel (7.0.2.2)
activesupport (= 7.0.2.2)
activerecord (7.0.2.2)
activemodel (= 7.0.2.2)
activesupport (= 7.0.2.2)
activesupport (7.0.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
concurrent-ruby (1.1.8)
diff-lcs (1.4.4)
i18n (1.8.10)
concurrent-ruby (1.1.9)
diff-lcs (1.5.0)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
minitest (5.14.4)
parallel (1.20.1)
parser (3.0.1.1)
minitest (5.15.0)
parallel (1.21.0)
parser (3.1.1.0)
ast (~> 2.4.1)
rack (2.2.3)
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.1.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.1)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.13.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.25.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
rubocop-ast (>= 1.15.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.5.0)
parser (>= 3.0.1.1)
rubocop-bsm (0.5.9)
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
rubocop-bsm (0.6.0)
rubocop (~> 1.0)
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
rubocop-performance (1.11.1)
rubocop-performance (1.13.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-rake (0.5.1)
rubocop
rubocop-rspec (2.3.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
rubocop-rspec (2.9.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
sqlite3 (1.4.2)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
zeitwerk (2.4.2)
unicode-display_width (2.1.0)

PLATFORMS
ruby
Expand All @@ -94,4 +85,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.1.4
2.3.6
5 changes: 3 additions & 2 deletions filterable-by.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'filterable-by'
s.version = '0.5.2'
s.version = '0.5.3'
s.authors = ['Dimitrij Denissenko']
s.email = ['dimitrij@blacksquaremedia.com']
s.summary = 'Generate white-listed filter scopes from URL parameter values'
Expand All @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.6'
s.required_ruby_version = '>= 2.7'

s.add_dependency 'activerecord'
s.add_dependency 'activesupport'
Expand All @@ -21,4 +21,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec'
s.add_development_dependency 'rubocop-bsm'
s.add_development_dependency 'sqlite3'
s.metadata['rubygems_mfa_required'] = 'true'
end
4 changes: 2 additions & 2 deletions lib/filterable_by.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def filterable_by(*names, &block)
end
end

# @param [Hash] hash the filter params
# @param [Hash|ActionController::Parameters] the filter params
# @return [ActiveRecord::Relation] the scoped relation
def filter_by(hash = nil, **opts)
if hash.nil?
hash = opts
opts = {}
end
scope = all
return scope unless hash.is_a?(Hash)
return scope unless hash.respond_to?(:key?) && hash.respond_to?(:[])

_filterable_by_config.each do |name, block|
next unless hash.key?(name)
Expand Down

0 comments on commit f7eb9a8

Please sign in to comment.