active_interaction-extras 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitignore +1 -0
- data/active_interaction-extras.gemspec +3 -1
- data/lib/active_interaction/extras/filter_extensions/object_classes.rb +2 -0
- data/lib/active_interaction/extras/filters/anything_filter.rb +9 -2
- data/lib/active_interaction/extras/filters/uuid_filter.rb +6 -1
- data/lib/active_interaction/extras/model_fields.rb +15 -12
- data/lib/active_interaction/extras/strong_params.rb +2 -0
- data/lib/active_interaction/extras/version.rb +1 -1
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 355913c4e3805b1373112d39fe9e686d6f1ae8b1cd7f2bca289443fd0cd37f63
|
4
|
+
data.tar.gz: f0e1a1611ca60b7199db6e18dc8152aa36fa76dde81cacfba1a6290a143ae544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256a1e71cd64571c76418ab9a4688d827ca2f98d589610af9445ea084ef018646a28ad095b32df776163530a6c544c85d9a22e9732aaa8de85829d47c841306f
|
7
|
+
data.tar.gz: 38cea9d7580d1c9966b9f4b70168e10cd8f7f8548605d040f4ded80ee70040032f6e9bbca9c6ed1b22f2896ed9056192a7df003eac1e6dd299a5cfcbeafbfffe
|
data/.github/workflows/ci.yml
CHANGED
@@ -19,7 +19,7 @@ jobs:
|
|
19
19
|
runs-on: ubuntu-latest
|
20
20
|
strategy:
|
21
21
|
matrix:
|
22
|
-
ruby-version: ['2.
|
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@
|
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
@@ -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", ">=
|
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
|
|
@@ -3,7 +3,14 @@
|
|
3
3
|
class ActiveInteraction::Extras::Filters::AnythingFilter < ActiveInteraction::Filter
|
4
4
|
register :anything
|
5
5
|
|
6
|
-
def matches?(
|
7
|
-
|
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
|
@@ -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
|
-
|
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
|
74
|
-
super
|
75
|
-
self.class.filters.each do |name, filter|
|
76
|
-
next if given?(name)
|
75
|
+
def initialize(...)
|
76
|
+
super
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
self.class.filters.each do |name, filter|
|
79
|
+
next if inputs.given?(name)
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
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.'
|
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
|
+
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:
|
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:
|
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:
|
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: '
|
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.
|
232
|
+
rubygems_version: 3.3.26
|
227
233
|
signing_key:
|
228
234
|
specification_version: 4
|
229
235
|
summary: Extensions for active_interaction gem
|