active_interaction 3.8.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +192 -0
- data/README.md +93 -107
- data/lib/active_interaction.rb +1 -7
- data/lib/active_interaction/base.rb +44 -67
- data/lib/active_interaction/concerns/active_modelable.rb +1 -3
- data/lib/active_interaction/concerns/active_recordable.rb +1 -6
- data/lib/active_interaction/concerns/hashable.rb +0 -1
- data/lib/active_interaction/concerns/missable.rb +0 -1
- data/lib/active_interaction/concerns/runnable.rb +7 -14
- data/lib/active_interaction/errors.rb +4 -19
- data/lib/active_interaction/filter.rb +66 -37
- data/lib/active_interaction/filter_column.rb +0 -3
- data/lib/active_interaction/filters/abstract_date_time_filter.rb +38 -36
- data/lib/active_interaction/filters/abstract_numeric_filter.rb +27 -17
- data/lib/active_interaction/filters/array_filter.rb +59 -36
- data/lib/active_interaction/filters/boolean_filter.rb +26 -12
- data/lib/active_interaction/filters/date_filter.rb +1 -2
- data/lib/active_interaction/filters/date_time_filter.rb +1 -2
- data/lib/active_interaction/filters/decimal_filter.rb +10 -28
- data/lib/active_interaction/filters/file_filter.rb +6 -5
- data/lib/active_interaction/filters/float_filter.rb +1 -2
- data/lib/active_interaction/filters/hash_filter.rb +37 -27
- data/lib/active_interaction/filters/integer_filter.rb +7 -8
- data/lib/active_interaction/filters/interface_filter.rb +48 -14
- data/lib/active_interaction/filters/object_filter.rb +23 -50
- data/lib/active_interaction/filters/record_filter.rb +10 -35
- data/lib/active_interaction/filters/string_filter.rb +21 -12
- data/lib/active_interaction/filters/symbol_filter.rb +13 -7
- data/lib/active_interaction/filters/time_filter.rb +24 -19
- data/lib/active_interaction/grouped_input.rb +0 -3
- data/lib/active_interaction/inputs.rb +120 -0
- data/lib/active_interaction/modules/validation.rb +9 -12
- data/lib/active_interaction/version.rb +1 -3
- data/spec/active_interaction/base_spec.rb +38 -99
- data/spec/active_interaction/concerns/active_modelable_spec.rb +0 -2
- data/spec/active_interaction/concerns/active_recordable_spec.rb +0 -2
- data/spec/active_interaction/concerns/hashable_spec.rb +0 -2
- data/spec/active_interaction/concerns/missable_spec.rb +0 -2
- data/spec/active_interaction/concerns/runnable_spec.rb +26 -12
- data/spec/active_interaction/errors_spec.rb +4 -25
- data/spec/active_interaction/filter_column_spec.rb +0 -2
- data/spec/active_interaction/filter_spec.rb +0 -2
- data/spec/active_interaction/filters/abstract_date_time_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/abstract_numeric_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/array_filter_spec.rb +51 -14
- data/spec/active_interaction/filters/boolean_filter_spec.rb +58 -4
- data/spec/active_interaction/filters/date_filter_spec.rb +43 -3
- data/spec/active_interaction/filters/date_time_filter_spec.rb +43 -3
- data/spec/active_interaction/filters/decimal_filter_spec.rb +57 -3
- data/spec/active_interaction/filters/file_filter_spec.rb +1 -3
- data/spec/active_interaction/filters/float_filter_spec.rb +60 -4
- data/spec/active_interaction/filters/hash_filter_spec.rb +19 -9
- data/spec/active_interaction/filters/integer_filter_spec.rb +49 -7
- data/spec/active_interaction/filters/interface_filter_spec.rb +397 -24
- data/spec/active_interaction/filters/object_filter_spec.rb +23 -59
- data/spec/active_interaction/filters/record_filter_spec.rb +23 -49
- data/spec/active_interaction/filters/string_filter_spec.rb +15 -3
- data/spec/active_interaction/filters/symbol_filter_spec.rb +15 -3
- data/spec/active_interaction/filters/time_filter_spec.rb +65 -3
- data/spec/active_interaction/grouped_input_spec.rb +0 -2
- data/spec/active_interaction/i18n_spec.rb +3 -7
- data/spec/active_interaction/{modules/input_processor_spec.rb → inputs_spec.rb} +35 -5
- data/spec/active_interaction/integration/array_interaction_spec.rb +18 -22
- data/spec/active_interaction/integration/boolean_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/date_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/date_time_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/file_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/float_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/hash_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/integer_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/interface_interaction_spec.rb +1 -3
- data/spec/active_interaction/integration/object_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/string_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/symbol_interaction_spec.rb +0 -2
- data/spec/active_interaction/integration/time_interaction_spec.rb +14 -18
- data/spec/active_interaction/modules/validation_spec.rb +1 -3
- data/spec/spec_helper.rb +2 -6
- data/spec/support/concerns.rb +0 -2
- data/spec/support/filters.rb +13 -9
- data/spec/support/interactions.rb +22 -14
- metadata +81 -57
- data/lib/active_interaction/backports.rb +0 -59
- data/lib/active_interaction/filters/abstract_filter.rb +0 -19
- data/lib/active_interaction/modules/input_processor.rb +0 -52
- data/spec/active_interaction/filters/abstract_filter_spec.rb +0 -8
@@ -1,59 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'active_support/core_ext'
|
5
|
-
|
6
|
-
module ActiveInteraction
|
7
|
-
class Errors # rubocop:disable Style/Documentation
|
8
|
-
# Required for Rails < 5.
|
9
|
-
#
|
10
|
-
# Extracted from active_model-errors_details 1.2.0. Modified to add support
|
11
|
-
# for ActiveModel 3.2.0.
|
12
|
-
module Details
|
13
|
-
extend ActiveSupport::Concern
|
14
|
-
|
15
|
-
CALLBACKS_OPTIONS = ::ActiveModel::Errors::CALLBACKS_OPTIONS
|
16
|
-
private_constant :CALLBACKS_OPTIONS
|
17
|
-
MESSAGE_OPTIONS = [:message].freeze
|
18
|
-
private_constant :MESSAGE_OPTIONS
|
19
|
-
|
20
|
-
included do
|
21
|
-
attr_reader :details
|
22
|
-
|
23
|
-
%w[initialize initialize_dup add clear delete].each do |method|
|
24
|
-
alias_method_chain method, :details
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize_with_details(base)
|
29
|
-
@details = Hash.new { |details, attribute| details[attribute] = [] }
|
30
|
-
initialize_without_details(base)
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize_dup_with_details(other)
|
34
|
-
@details = other.details.deep_dup
|
35
|
-
initialize_dup_without_details(other)
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_with_details(attribute, message = :invalid, options = {})
|
39
|
-
message = message.call if message.respond_to?(:call)
|
40
|
-
|
41
|
-
error = options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS)
|
42
|
-
.merge(error: message)
|
43
|
-
details[attribute].push(error)
|
44
|
-
add_without_details(attribute, message, options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def clear_with_details
|
48
|
-
details.clear
|
49
|
-
clear_without_details
|
50
|
-
end
|
51
|
-
|
52
|
-
def delete_with_details(attribute)
|
53
|
-
details.delete(attribute)
|
54
|
-
delete_without_details(attribute)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
include Details unless method_defined?(:details)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module ActiveInteraction
|
5
|
-
# @abstract
|
6
|
-
#
|
7
|
-
# Common logic for filters that can guess the class they operator on based on
|
8
|
-
# their name.
|
9
|
-
#
|
10
|
-
# @private
|
11
|
-
class AbstractFilter < Filter
|
12
|
-
private
|
13
|
-
|
14
|
-
# @return [Class]
|
15
|
-
def klass
|
16
|
-
@klass ||= Object.const_get(self.class.slug.to_s.camelize, false)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module ActiveInteraction
|
5
|
-
# Groups inputs ending in "(*N*i)" into {GroupedInput}.
|
6
|
-
#
|
7
|
-
# @since 1.2.0
|
8
|
-
#
|
9
|
-
# @private
|
10
|
-
module InputProcessor
|
11
|
-
class << self
|
12
|
-
GROUPED_INPUT_PATTERN = /\A(.+)\((\d+)i\)\z/
|
13
|
-
private_constant :GROUPED_INPUT_PATTERN
|
14
|
-
|
15
|
-
# Checking `syscall` is the result of what appears to be a bug in Ruby.
|
16
|
-
# https://bugs.ruby-lang.org/issues/15597
|
17
|
-
def reserved?(name)
|
18
|
-
name.to_s.start_with?('_interaction_') ||
|
19
|
-
name == :syscall ||
|
20
|
-
(
|
21
|
-
Base.method_defined?(name) &&
|
22
|
-
!Object.method_defined?(name)
|
23
|
-
) ||
|
24
|
-
(
|
25
|
-
Base.private_method_defined?(name) &&
|
26
|
-
!Object.private_method_defined?(name)
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def process(inputs)
|
31
|
-
inputs.stringify_keys.sort.each_with_object({}) do |(k, v), h|
|
32
|
-
next if reserved?(k)
|
33
|
-
|
34
|
-
if (match = GROUPED_INPUT_PATTERN.match(k))
|
35
|
-
assign_to_group!(h, *match.captures, v)
|
36
|
-
else
|
37
|
-
h[k.to_sym] = v
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def assign_to_group!(inputs, key, index, value)
|
45
|
-
key = key.to_sym
|
46
|
-
|
47
|
-
inputs[key] = GroupedInput.new unless inputs[key].is_a?(GroupedInput)
|
48
|
-
inputs[key][index] = value
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|