active_interaction-extras 1.0.4 → 1.1.0

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: e7c9ab1b398885ce07d041afd0698600f69ac5813434822945c5e1247e81e9a5
4
- data.tar.gz: b8e73b105796596890f5518823c430c02e402c5d5aa4be353617b7bddae65182
3
+ metadata.gz: 355913c4e3805b1373112d39fe9e686d6f1ae8b1cd7f2bca289443fd0cd37f63
4
+ data.tar.gz: f0e1a1611ca60b7199db6e18dc8152aa36fa76dde81cacfba1a6290a143ae544
5
5
  SHA512:
6
- metadata.gz: f983de2973a1aae555f1576ec2eca88de323a714e8a0e778b2be96a15b29486cc0dfe0f03219ccb800b3354421c9dc138fd50324f992e7b415bd20b634360b54
7
- data.tar.gz: 64b07f5287072bf90156987a0ec823b73341dc021e2b224c98f40dacbfa80240bd71b83d141323168a33e125fedb73d7547d7a919e0b3e4b7d603cd37743dc49
6
+ metadata.gz: 256a1e71cd64571c76418ab9a4688d827ca2f98d589610af9445ea084ef018646a28ad095b32df776163530a6c544c85d9a22e9732aaa8de85829d47c841306f
7
+ data.tar.gz: 38cea9d7580d1c9966b9f4b70168e10cd8f7f8548605d040f4ded80ee70040032f6e9bbca9c6ed1b22f2896ed9056192a7df003eac1e6dd299a5cfcbeafbfffe
@@ -19,7 +19,7 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
22
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
@@ -27,7 +27,7 @@ jobs:
27
27
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
28
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
29
  # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
30
+ uses: ruby/setup-ruby@v1
31
31
  with:
32
32
  ruby-version: ${{ matrix.ruby-version }}
33
33
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ .ruby-version
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
17
17
  "changelog_uri" => "https://github.com/antulik/active_interaction-extras/blob/master/CHANGELOG.md",
18
18
  }
19
19
 
20
+ spec.required_ruby_version = '>= 2.7'
21
+
20
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
23
  f.match(%r{^(test|spec|features)/})
22
24
  end
@@ -24,7 +26,7 @@ Gem::Specification.new do |spec|
24
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
27
  spec.require_paths = ["lib"]
26
28
 
27
- spec.add_dependency "active_interaction", ">= 4.0.2"
29
+ spec.add_dependency "active_interaction", ">= 5.0", "< 6.0"
28
30
  spec.add_dependency "activemodel", ">= 6.0"
29
31
  spec.add_dependency "activesupport", ">= 6.0"
30
32
 
@@ -29,6 +29,8 @@ module ActiveInteraction::Extras::FilterExtensions::ObjectClasses
29
29
 
30
30
  def matches?(value)
31
31
  if polymorphic?
32
+ return false if value == nil
33
+
32
34
  class_list.any? { |klass| value.class <= klass }
33
35
  else
34
36
  super
@@ -3,7 +3,14 @@
3
3
  class ActiveInteraction::Extras::Filters::AnythingFilter < ActiveInteraction::Filter
4
4
  register :anything
5
5
 
6
- def matches?(_object)
7
- true
6
+ def matches?(value)
7
+ if value == nil && default?
8
+ # as per v5 there is no way to know if value of `nil` is given by caller or
9
+ # is a default value when it's missing. We want to maintain standard default
10
+ # behaviour when value is `nil`. Returning `false` will trigger default value
11
+ false
12
+ else
13
+ true
14
+ end
8
15
  end
9
16
  end
@@ -10,6 +10,11 @@ class ActiveInteraction::Extras::Filters::UUIDFilter < ActiveInteraction::String
10
10
  end
11
11
 
12
12
  def convert(value)
13
- super&.presence
13
+ value, error = super
14
+ if error
15
+ [value, error]
16
+ else
17
+ [value&.presence, nil]
18
+ end
14
19
  end
15
20
  end
@@ -6,7 +6,9 @@ module ActiveInteraction::Extras::ModelFields
6
6
  # returns hash of all model fields and their values
7
7
  def model_fields(model_name)
8
8
  fields = self.class.model_field_cache[model_name]
9
- inputs.slice(*fields)
9
+ fields.to_h do |field|
10
+ [field, public_send(field)]
11
+ end
10
12
  end
11
13
 
12
14
  # returns hash of only changed model fields and their values
@@ -19,7 +21,7 @@ module ActiveInteraction::Extras::ModelFields
19
21
  # returns hash of only given model fields and their values
20
22
  def given_model_fields(model_name)
21
23
  model_fields(model_name).select do |field, _value|
22
- given?(field)
24
+ inputs.given?(field)
23
25
  end
24
26
  end
25
27
 
@@ -65,22 +67,23 @@ module ActiveInteraction::Extras::ModelFields
65
67
  value_changed = send(model_field).send(field) != send(field)
66
68
  end
67
69
 
68
- given?(field) && value_changed
70
+ inputs.given?(field) && value_changed
69
71
  end
70
72
  end
71
73
 
72
74
  # overwritten to pre-populate model fields
73
- def populate_filters_and_inputs(_inputs)
74
- super.tap do
75
- self.class.filters.each do |name, filter|
76
- next if given?(name)
75
+ def initialize(...)
76
+ super
77
77
 
78
- model_field = self.class.model_field_cache_inverse[name]
79
- next if model_field.nil?
78
+ self.class.filters.each do |name, filter|
79
+ next if inputs.given?(name)
80
80
 
81
- value = public_send(model_field)&.public_send(name)
82
- public_send("#{name}=", filter.clean(value, self))
83
- end
81
+ model_field = self.class.model_field_cache_inverse[name]
82
+ next if model_field.nil?
83
+
84
+ value = public_send(model_field)&.public_send(name)
85
+ input = filter.process(value, self)
86
+ public_send("#{name}=", input.value)
84
87
  end
85
88
  end
86
89
 
@@ -5,6 +5,8 @@ module ActiveInteraction::Extras::StrongParams
5
5
  # TODO: whitelist :params and :form_params, so they could not be used as filters
6
6
  return super if self.class.filters.key?(:params) || self.class.filters.key?(:form_params)
7
7
 
8
+ return super if %i[fetch key? merge].any? { |m| !inputs.respond_to?(m) }
9
+
8
10
  if inputs.key?(:params) && inputs.key?(:form_params)
9
11
  raise ArgumentError, 'Both options :params and :form_params are given. ' \
10
12
  'One or none are accepted.'
@@ -1,5 +1,5 @@
1
1
  module ActiveInteraction
2
2
  module Extras
3
- VERSION = "1.0.4"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_interaction-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Katunin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_interaction
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.2
19
+ version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 4.0.2
29
+ version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activemodel
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -216,14 +222,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
222
  requirements:
217
223
  - - ">="
218
224
  - !ruby/object:Gem::Version
219
- version: '0'
225
+ version: '2.7'
220
226
  required_rubygems_version: !ruby/object:Gem::Requirement
221
227
  requirements:
222
228
  - - ">="
223
229
  - !ruby/object:Gem::Version
224
230
  version: '0'
225
231
  requirements: []
226
- rubygems_version: 3.1.4
232
+ rubygems_version: 3.3.26
227
233
  signing_key:
228
234
  specification_version: 4
229
235
  summary: Extensions for active_interaction gem