active_interaction 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/active_interaction/base.rb +19 -20
- data/lib/active_interaction/errors.rb +1 -13
- data/lib/active_interaction/filters/array_filter.rb +7 -5
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +0 -35
- data/spec/active_interaction/filters/array_filter_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b6d048d5a1bc4790a7852753a5bb79b74ddcef73e88603692fc0c580a28247c
|
4
|
+
data.tar.gz: 62091b8494eee0cd2d90b64fb9540067e0b98446403af42e21ddb45df2891f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf7ba20068a6d5aee70730136d891d1bc4ce94d49ec8d7558805e3c6e017ba8560943581c31a99760890572a5b8d4121ec4ec8c8d639c3a29878505d56f09221
|
7
|
+
data.tar.gz: 12a9fb539e434435065fde8671905b34fa742e4ebe5b030992b2d0ed58c17040cbaa9b2125a7a391311bd64659aa24416aa6c2d2b3ab151cadde018be1ff86fb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [4.0.2][] (2021-06-22)
|
2
|
+
|
3
|
+
## Fix
|
4
|
+
|
5
|
+
- [#505][] - Nested Interface filters using the `:methods` option threw an error.
|
6
|
+
|
1
7
|
# [4.0.1][] (2021-05-26)
|
2
8
|
|
3
9
|
## Fix
|
@@ -938,6 +944,8 @@ Example.run
|
|
938
944
|
|
939
945
|
- Initial release.
|
940
946
|
|
947
|
+
[4.0.2]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.1...v4.0.2
|
948
|
+
[4.0.1]: https://github.com/AaronLasseigne/active_interaction/compare/v4.0.0...v4.0.1
|
941
949
|
[4.0.0]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.3...v4.0.0
|
942
950
|
[3.8.3]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.2...v3.8.3
|
943
951
|
[3.8.2]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.1...v3.8.2
|
@@ -1143,3 +1151,5 @@ Example.run
|
|
1143
1151
|
[#486]: https://github.com/AaronLasseigne/active_interaction/issues/486
|
1144
1152
|
[#392]: https://github.com/AaronLasseigne/active_interaction/issues/392
|
1145
1153
|
[#398]: https://github.com/AaronLasseigne/active_interaction/issues/398
|
1154
|
+
[#495]: https://github.com/AaronLasseigne/active_interaction/issues/495
|
1155
|
+
[#505]: https://github.com/AaronLasseigne/active_interaction/issues/505
|
@@ -191,10 +191,7 @@ module ActiveInteraction
|
|
191
191
|
#
|
192
192
|
# @return [Hash{Symbol => Object}] All inputs passed to {.run} or {.run!}.
|
193
193
|
def inputs
|
194
|
-
@
|
195
|
-
.each_key.with_object(ActiveInteraction::Inputs.new) do |name, h|
|
196
|
-
h[name] = public_send(name)
|
197
|
-
end.freeze
|
194
|
+
@_interaction_inputs
|
198
195
|
end
|
199
196
|
|
200
197
|
# Returns `true` if the given key was in the hash passed to {.run}.
|
@@ -238,7 +235,7 @@ module ActiveInteraction
|
|
238
235
|
# rubocop:disable all
|
239
236
|
def given?(input, *rest)
|
240
237
|
filter_level = self.class
|
241
|
-
input_level = @
|
238
|
+
input_level = @_interaction_raw_inputs
|
242
239
|
|
243
240
|
[input, *rest].each do |key_or_index|
|
244
241
|
if key_or_index.is_a?(Symbol) || key_or_index.is_a?(String)
|
@@ -288,27 +285,29 @@ module ActiveInteraction
|
|
288
285
|
|
289
286
|
# @param inputs [Hash{Symbol => Object}]
|
290
287
|
def process_inputs(inputs)
|
291
|
-
@
|
288
|
+
@_interaction_raw_inputs = inputs
|
292
289
|
|
293
|
-
inputs
|
294
|
-
next if ActiveInteraction::Inputs.reserved?(key)
|
295
|
-
|
296
|
-
populate_reader(key, value)
|
297
|
-
end
|
298
|
-
|
299
|
-
populate_filters(ActiveInteraction::Inputs.process(inputs))
|
290
|
+
populate_filters_and_inputs(ActiveInteraction::Inputs.process(inputs))
|
300
291
|
end
|
301
292
|
|
302
|
-
def
|
303
|
-
|
304
|
-
end
|
293
|
+
def populate_filters_and_inputs(inputs)
|
294
|
+
@_interaction_inputs = ActiveInteraction::Inputs.new
|
305
295
|
|
306
|
-
def populate_filters(inputs)
|
307
296
|
self.class.filters.each do |name, filter|
|
308
|
-
|
309
|
-
|
310
|
-
|
297
|
+
value =
|
298
|
+
begin
|
299
|
+
filter.clean(inputs[name], self)
|
300
|
+
rescue InvalidValueError, MissingValueError, NoDefaultError
|
301
|
+
# #type_check will add errors if appropriate.
|
302
|
+
# We'll get the original value for the error.
|
303
|
+
inputs[name]
|
304
|
+
end
|
305
|
+
|
306
|
+
@_interaction_inputs[name] = value
|
307
|
+
public_send("#{name}=", value)
|
311
308
|
end
|
309
|
+
|
310
|
+
@_interaction_inputs.freeze
|
312
311
|
end
|
313
312
|
|
314
313
|
def type_check
|
@@ -98,11 +98,7 @@ module ActiveInteraction
|
|
98
98
|
#
|
99
99
|
# @return [Errors]
|
100
100
|
def merge!(other)
|
101
|
-
|
102
|
-
merge_details!(other)
|
103
|
-
else
|
104
|
-
merge_messages!(other)
|
105
|
-
end
|
101
|
+
merge_details!(other)
|
106
102
|
|
107
103
|
self
|
108
104
|
end
|
@@ -117,14 +113,6 @@ module ActiveInteraction
|
|
117
113
|
detail[:error].is_a?(Symbol)
|
118
114
|
end
|
119
115
|
|
120
|
-
def merge_messages!(other)
|
121
|
-
other.messages.each do |attribute, messages|
|
122
|
-
messages.each do |message|
|
123
|
-
merge_message!(attribute, message)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
116
|
def merge_message!(attribute, message)
|
129
117
|
unless attribute?(attribute)
|
130
118
|
message = full_message(attribute, message)
|
@@ -25,10 +25,12 @@ module ActiveInteraction
|
|
25
25
|
class ArrayFilter < Filter
|
26
26
|
include Missable
|
27
27
|
|
28
|
+
# The array starts with the class override key and then contains any
|
29
|
+
# additional options which halt explicit setting of the class.
|
28
30
|
FILTER_NAME_OR_OPTION = {
|
29
|
-
'ActiveInteraction::ObjectFilter' => :class,
|
30
|
-
'ActiveInteraction::RecordFilter' => :class,
|
31
|
-
'ActiveInteraction::InterfaceFilter' =>
|
31
|
+
'ActiveInteraction::ObjectFilter' => [:class].freeze,
|
32
|
+
'ActiveInteraction::RecordFilter' => [:class].freeze,
|
33
|
+
'ActiveInteraction::InterfaceFilter' => %i[from methods].freeze
|
32
34
|
}.freeze
|
33
35
|
private_constant :FILTER_NAME_OR_OPTION
|
34
36
|
|
@@ -71,9 +73,9 @@ module ActiveInteraction
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def add_option_in_place_of_name(klass, options)
|
74
|
-
if (
|
76
|
+
if (keys = FILTER_NAME_OR_OPTION[klass.to_s]) && (keys && options.keys).empty?
|
75
77
|
options.merge(
|
76
|
-
"#{
|
78
|
+
"#{keys.first}": name.to_s.singularize.camelize.to_sym
|
77
79
|
)
|
78
80
|
else
|
79
81
|
options
|
@@ -70,41 +70,6 @@ describe ActiveInteraction::Base do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context 'with a reader' do
|
74
|
-
let(:described_class) do
|
75
|
-
Class.new(TestInteraction) do
|
76
|
-
attr_reader :thing
|
77
|
-
|
78
|
-
validates :thing, presence: true
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'validation' do
|
83
|
-
context 'failing' do
|
84
|
-
it 'returns an invalid outcome' do
|
85
|
-
expect(interaction).to be_invalid
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'passing' do
|
90
|
-
before { inputs[:thing] = SecureRandom.hex }
|
91
|
-
|
92
|
-
it 'returns a valid outcome' do
|
93
|
-
expect(interaction).to be_valid
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'with a single input' do
|
99
|
-
let(:thing) { SecureRandom.hex }
|
100
|
-
before { inputs[:thing] = thing }
|
101
|
-
|
102
|
-
it 'sets the attribute' do
|
103
|
-
expect(interaction.thing).to eql thing
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
73
|
context 'with a filter' do
|
109
74
|
let(:described_class) { InteractionWithFilter }
|
110
75
|
|
@@ -127,6 +127,17 @@ describe ActiveInteraction::ArrayFilter, :filter do
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
130
|
+
|
131
|
+
context 'with a nested interface type' do
|
132
|
+
context 'with the methods option set' do
|
133
|
+
let(:block) { proc { public_send(:interface, methods: %i[to_s]) } }
|
134
|
+
|
135
|
+
it 'has a filter with the right option' do
|
136
|
+
expect(filter.filters[:'0'].options).to have_key(:methods)
|
137
|
+
expect(filter.filters[:'0'].options[:methods]).to eql %i[to_s]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
130
141
|
end
|
131
142
|
|
132
143
|
describe '#database_column_type' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|