active_interaction 4.0.1 → 4.0.2

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: 65047712d1df9c67700202a27f83054c30fccbdf3d7bf7e0478c01e5bea07fc8
4
- data.tar.gz: b39bb6c7d8784cf842eb266e3955fdbc1082c5a4f96c30bdcbdd10074294ea6d
3
+ metadata.gz: 1b6d048d5a1bc4790a7852753a5bb79b74ddcef73e88603692fc0c580a28247c
4
+ data.tar.gz: 62091b8494eee0cd2d90b64fb9540067e0b98446403af42e21ddb45df2891f9c
5
5
  SHA512:
6
- metadata.gz: 5ca04e342b3b82a29724e113600ca12bebdc303de3c66c51299fc490cd8686e3a062c77498ccd53e33f02a9dc0e05dc5a44ee26be911af6e59bfcca1b2d41d65
7
- data.tar.gz: a09744ecbd57a5c69ee845235942c2f2063bfb70f509a9bd6384f45690a35218e6c48c632b2388701f910746614b43b040803329e5310e24ea291267eddd3234
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
- @inputs ||= self.class.filters
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 = @_interaction_inputs
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
- @_interaction_inputs = inputs
288
+ @_interaction_raw_inputs = inputs
292
289
 
293
- inputs.each do |key, value|
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 populate_reader(key, value)
303
- instance_variable_set("@#{key}", value) if respond_to?(key)
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
- public_send("#{name}=", filter.clean(inputs[name], self))
309
- rescue InvalidValueError, MissingValueError, NoDefaultError
310
- nil # #type_check will add errors if appropriate.
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
- if other.respond_to?(:details)
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' => :from
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 (key = FILTER_NAME_OR_OPTION[klass.to_s]) && !options.key?(key)
76
+ if (keys = FILTER_NAME_OR_OPTION[klass.to_s]) && (keys && options.keys).empty?
75
77
  options.merge(
76
- "#{key}": name.to_s.singularize.camelize.to_sym
78
+ "#{keys.first}": name.to_s.singularize.camelize.to_sym
77
79
  )
78
80
  else
79
81
  options
@@ -4,5 +4,5 @@ module ActiveInteraction
4
4
  # The version number.
5
5
  #
6
6
  # @return [Gem::Version]
7
- VERSION = Gem::Version.new('4.0.1')
7
+ VERSION = Gem::Version.new('4.0.2')
8
8
  end
@@ -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.1
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-05-26 00:00:00.000000000 Z
12
+ date: 2021-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel