filterameter 0.2.0 → 0.4.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
  SHA256:
3
- metadata.gz: e753f63174bbf6eb6a0ad352fc518782bc092f5e9075bcd596d540c76ceb6ab1
4
- data.tar.gz: 14f544522f30cbf4d2d6fe54fb5e8a5e0310172fcc75007c087e9402359d6ae3
3
+ metadata.gz: 83338f9a61d92c1d562a5708a0268e647d52916960b4d750a75f3cd6107bee7a
4
+ data.tar.gz: a3036ffda002e4075a40be6225681bb67ed9b2f5c2534ecf5370aff70e7d375c
5
5
  SHA512:
6
- metadata.gz: 13b2457bf17e0cdd1d9b11075d4a5df015179b46000a2b3418d10ab5885bb5d2fc0435c59bfdae7668c2cf165973084ccd2a1403e95f32e1e40cef1a67849dfb
7
- data.tar.gz: 26b14da4bdc7e786dbd025af086dc9aadac131306c3ef82ea7ef8f73e72e7518e4de825d34ab80b51ed2b3052705060ebf87b6ae5dce56a8adc697f051928258
6
+ metadata.gz: c923a97b54f2da6ed9f2d17743213cde5f16f9525383ef1bbe7081f02ae69ac46553e398a5d5f45b5292f65b84d0a0a681fb198633b06d44eb0ab013a606338c
7
+ data.tar.gz: 5dae50a8f42ad0ac9a83dbe497f948f7dbabba29157daf5549478487f6c973a129ee514d04e40820467d3abb8111bf2430d82cf7495bf599e06225f7cb684a4b
@@ -1,12 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'filterameter/filter_declaration'
4
- require 'filterameter/filter_factory'
5
- require 'filterameter/filter_registry'
6
- require 'filterameter/log_subscriber'
7
- require 'filterameter/parameters_base'
8
- require 'filterameter/query_builder'
9
-
10
3
  module Filterameter
11
4
  module Coordinators
12
5
  # = Coordinators Base
@@ -7,8 +7,6 @@ require 'action_dispatch'
7
7
  require 'action_controller/metal/live'
8
8
  require 'action_controller/metal/strong_parameters'
9
9
 
10
- require 'filterameter/coordinators/base'
11
-
12
10
  module Filterameter
13
11
  module Coordinators
14
12
  # = Controller Filters
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'filterameter/filterable'
4
- require 'filterameter/coordinators/controller_coordinator'
5
-
6
3
  module Filterameter
7
4
  # = Declarative Controller Filters
8
5
  #
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'filterameter/coordinators/query_coordinator'
4
- require 'filterameter/filterable'
5
- require 'filterameter/query_builder'
6
-
7
3
  module Filterameter
8
4
  # = Declarative Filters
9
5
  #
@@ -9,8 +9,8 @@ module Filterameter
9
9
  # explicitly by adding a call to `filter_model`.
10
10
  class CannotDetermineModelError < FilterameterError
11
11
  def initialize(name, path)
12
- super "Cannot determine model name from controller name #{value_and_classify(name)} " \
13
- "or path #{value_and_classify(path)}. Declare the model explicitly with filter_model."
12
+ super("Cannot determine model name from controller name #{value_and_classify(name)} " \
13
+ "or path #{value_and_classify(path)}. Declare the model explicitly with filter_model.")
14
14
  end
15
15
 
16
16
  private
@@ -6,7 +6,3 @@ module Filterameter
6
6
  end
7
7
  end
8
8
  end
9
-
10
- require 'filterameter/exceptions/cannot_determine_model_error'
11
- require 'filterameter/exceptions/validation_error'
12
- require 'filterameter/exceptions/undeclared_parameter_error'
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/array/wrap'
4
- require 'filterameter/options/partial_options'
5
4
 
6
5
  module Filterameter
7
6
  # = Filter Declaration
@@ -1,14 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'filterameter/filters/arel_filter'
4
- require 'filterameter/filters/attribute_filter'
5
- require 'filterameter/filters/conditional_scope_filter'
6
- require 'filterameter/filters/matches_filter'
7
- require 'filterameter/filters/maximum_filter'
8
- require 'filterameter/filters/minimum_filter'
9
- require 'filterameter/filters/nested_filter'
10
- require 'filterameter/filters/scope_filter'
11
-
12
3
  module Filterameter
13
4
  # = Filter Factory
14
5
  #
@@ -16,13 +16,14 @@ module Filterameter
16
16
  end
17
17
 
18
18
  def add_filter(parameter_name, options)
19
- @declarations[parameter_name.to_s] = Filterameter::FilterDeclaration.new(parameter_name, options).tap do |fd|
20
- add_declarations_for_range(fd, options, parameter_name) if fd.range_enabled?
19
+ name = parameter_name.to_s
20
+ @declarations[name] = Filterameter::FilterDeclaration.new(name, options).tap do |fd|
21
+ add_declarations_for_range(fd, options, name) if fd.range_enabled?
21
22
  end
22
23
  end
23
24
 
24
- def fetch(name)
25
- name = name.to_s
25
+ def fetch(parameter_name)
26
+ name = parameter_name.to_s
26
27
  @filters.fetch(name) do
27
28
  raise Filterameter::Exceptions::UndeclaredParameterError, name unless @declarations.keys.include?(name)
28
29
 
@@ -1,82 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Options
4
- # = Partial Options
5
- #
6
- # Class PartialOptions parses the options passed in as partial, then exposes those. Here are the options along with
7
- # their valid values:
8
- # - match: anywhere (default), from_start, dynamic
9
- # - case_sensitive: true, false (default)
10
- #
11
- # Options may be specified by passing a hash with the option keys:
12
- #
13
- # partial: { match: :from_start, case_sensitive: true }
14
- #
15
- # There are two shortcuts: the partial option can be declared with `true`, which just uses the defaults; or the
16
- # partial option can be declared with the match option directly, such as partial: :from_start.
17
- class PartialOptions
18
- VALID_OPTIONS = %i[match case_sensitive].freeze
19
- VALID_MATCH_OPTIONS = %w[anywhere from_start dynamic].freeze
3
+ module Filterameter
4
+ module Options
5
+ # = Partial Options
6
+ #
7
+ # Class PartialOptions parses the options passed in as partial, then exposes those. Here are the options along with
8
+ # their valid values:
9
+ # - match: anywhere (default), from_start, dynamic
10
+ # - case_sensitive: true, false (default)
11
+ #
12
+ # Options may be specified by passing a hash with the option keys:
13
+ #
14
+ # partial: { match: :from_start, case_sensitive: true }
15
+ #
16
+ # There are two shortcuts: the partial option can be declared with `true`, which just uses the defaults; or the
17
+ # partial option can be declared with the match option directly, such as partial: :from_start.
18
+ class PartialOptions
19
+ VALID_OPTIONS = %i[match case_sensitive].freeze
20
+ VALID_MATCH_OPTIONS = %w[anywhere from_start dynamic].freeze
20
21
 
21
- def initialize(options)
22
- @match = 'anywhere'
23
- @case_sensitive = false
22
+ def initialize(options)
23
+ @match = 'anywhere'
24
+ @case_sensitive = false
24
25
 
25
- case options
26
- when TrueClass
27
- nil
28
- when Hash
29
- evaluate_hash(options)
30
- when String, Symbol
31
- assign_match(options)
26
+ case options
27
+ when TrueClass
28
+ nil
29
+ when Hash
30
+ evaluate_hash(options)
31
+ when String, Symbol
32
+ assign_match(options)
33
+ end
32
34
  end
33
- end
34
35
 
35
- def case_sensitive?
36
- @case_sensitive
37
- end
36
+ def case_sensitive?
37
+ @case_sensitive
38
+ end
38
39
 
39
- def match_anywhere?
40
- @match == 'anywhere'
41
- end
40
+ def match_anywhere?
41
+ @match == 'anywhere'
42
+ end
42
43
 
43
- def match_from_start?
44
- @match == 'from_start'
45
- end
44
+ def match_from_start?
45
+ @match == 'from_start'
46
+ end
46
47
 
47
- def match_dynamically?
48
- @match == 'dynamic'
49
- end
48
+ def match_dynamically?
49
+ @match == 'dynamic'
50
+ end
50
51
 
51
- private
52
+ private
52
53
 
53
- def evaluate_hash(options)
54
- options.assert_valid_keys(:match, :case_sensitive)
55
- assign_match(options[:match]) if options.key?(:match)
56
- assign_case_sensitive(options[:case_sensitive]) if options.key?(:case_sensitive)
57
- end
54
+ def evaluate_hash(options)
55
+ options.assert_valid_keys(:match, :case_sensitive)
56
+ assign_match(options[:match]) if options.key?(:match)
57
+ assign_case_sensitive(options[:case_sensitive]) if options.key?(:case_sensitive)
58
+ end
58
59
 
59
- def assign_match(value)
60
- validate_match(value)
61
- @match = value.to_s
62
- end
60
+ def assign_match(value)
61
+ validate_match(value)
62
+ @match = value.to_s
63
+ end
63
64
 
64
- def validate_match(value)
65
- return if VALID_MATCH_OPTIONS.include? value.to_s
65
+ def validate_match(value)
66
+ return if VALID_MATCH_OPTIONS.include? value.to_s
66
67
 
67
- raise ArgumentError,
68
- "Invalid match option for partial: #{value}. Valid options are #{VALID_MATCH_OPTIONS.to_sentence}"
69
- end
68
+ raise ArgumentError,
69
+ "Invalid match option for partial: #{value}. Valid options are #{VALID_MATCH_OPTIONS.to_sentence}"
70
+ end
70
71
 
71
- def assign_case_sensitive(value)
72
- validate_case_sensitive(value)
73
- @case_sensitive = value
74
- end
72
+ def assign_case_sensitive(value)
73
+ validate_case_sensitive(value)
74
+ @case_sensitive = value
75
+ end
75
76
 
76
- def validate_case_sensitive(value)
77
- return if value.is_a?(TrueClass) || value.is_a?(FalseClass)
77
+ def validate_case_sensitive(value)
78
+ return if value.is_a?(TrueClass) || value.is_a?(FalseClass)
78
79
 
79
- raise ArgumentError, "Invalid case_sensitive option for partial: #{value}. Valid options are true and false."
80
+ raise ArgumentError, "Invalid case_sensitive option for partial: #{value}. Valid options are true and false."
81
+ end
80
82
  end
81
83
  end
82
84
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'active_model/attribute_assignment'
4
4
  require 'active_model/validations'
5
- require 'filterameter/validators/inclusion_validator'
6
5
 
7
6
  module Filterameter
8
7
  # = Parameters
@@ -11,7 +11,7 @@ module Filterameter
11
11
  end
12
12
 
13
13
  def build_query(filter_params, starting_query = nil)
14
- valid_filters(filter_params)
14
+ valid_filters(filter_params.stringify_keys)
15
15
  .tap { |parameters| convert_min_and_max_to_range(parameters) }
16
16
  .reduce(starting_query || @default_query) do |query, (name, value)|
17
17
  add_filter_parameter_to_query(query, name, value)
@@ -64,7 +64,15 @@ module Filterameter
64
64
  raise Filterameter::Exceptions::ValidationError, validator.errors
65
65
  end
66
66
 
67
- filter_params.except(*validator.errors.attribute_names.map(&:to_s))
67
+ filter_params.except(*invalid_attributes(validator.errors).map(&:to_s))
68
+ end
69
+
70
+ def invalid_attributes(errors)
71
+ if errors.respond_to? :attribute_names
72
+ errors.attribute_names
73
+ else # pre rails 6.1
74
+ errors.keys
75
+ end
68
76
  end
69
77
 
70
78
  def validator_class
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filterameter
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/filterameter.rb CHANGED
@@ -1,17 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'filterameter/configuration'
4
- require 'filterameter/declarative_controller_filters'
5
- require 'filterameter/declarative_filters'
6
- require 'filterameter/exceptions'
3
+ require 'zeitwerk'
4
+
5
+ loader = Zeitwerk::Loader.for_gem
6
+ loader.setup # ready!
7
7
 
8
8
  # = Filterameter
9
- #
10
- # Module Filterameter can be mixed into a controller to provide the DSL to describe each controller's filters.
11
- #
12
- # The model class must be declared if it cannot be derived. It can be derived if (A) the model is not namespaced and its
13
- # name matches the controller name (for example BrandsController -> Brand) or (B) both the controller and model share
14
- # the same namespace and name.
15
9
  module Filterameter
16
10
  class << self
17
11
  attr_writer :configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterameter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.2
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.2
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: guard
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,56 +86,70 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 1.1.4
89
+ version: 1.5.4
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.1.4
96
+ version: 1.5.4
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec-rails
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '3.9'
103
+ version: '4.0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '3.9'
110
+ version: '4.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 1.22.3
117
+ version: 1.60.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.60.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-packaging
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.2
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: 1.22.3
138
+ version: 0.5.2
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: rubocop-rails
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: 2.8.1
145
+ version: 2.23.1
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: 2.8.1
152
+ version: 2.23.1
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: simplecov
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +164,7 @@ dependencies:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0.18'
139
- description: Enable filter parameters to be declared in controllers.
167
+ description: Enable filter parameters to be declared in query classes or controllers.
140
168
  email:
141
169
  - todd@rockridgesolutions.com
142
170
  executables: []
@@ -194,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
222
  - !ruby/object:Gem::Version
195
223
  version: '0'
196
224
  requirements: []
197
- rubygems_version: 3.0.8
225
+ rubygems_version: 3.4.10
198
226
  signing_key:
199
227
  specification_version: 4
200
- summary: Declarative Filter Parameters for Rails Controllers
228
+ summary: Declarative Filter Parameters
201
229
  test_files: []