activeinteractor 1.2.2 → 2.0.0.alpha.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/LICENSE +1 -1
  4. data/README.md +4 -64
  5. data/lib/active_interactor/base.rb +77 -29
  6. data/lib/active_interactor/errors.rb +12 -0
  7. data/lib/active_interactor/result.rb +73 -0
  8. data/lib/active_interactor.rb +3 -101
  9. data/sig/active_interactor.rbs +3 -0
  10. metadata +23 -86
  11. data/.yardopts +0 -12
  12. data/lib/active_interactor/config.rb +0 -60
  13. data/lib/active_interactor/configurable.rb +0 -53
  14. data/lib/active_interactor/context/attributes.rb +0 -179
  15. data/lib/active_interactor/context/base.rb +0 -333
  16. data/lib/active_interactor/context/errors.rb +0 -57
  17. data/lib/active_interactor/context/loader.rb +0 -50
  18. data/lib/active_interactor/context/status.rb +0 -106
  19. data/lib/active_interactor/error.rb +0 -46
  20. data/lib/active_interactor/interactor/callbacks.rb +0 -293
  21. data/lib/active_interactor/interactor/context.rb +0 -378
  22. data/lib/active_interactor/interactor/perform.rb +0 -260
  23. data/lib/active_interactor/interactor/worker.rb +0 -120
  24. data/lib/active_interactor/models.rb +0 -50
  25. data/lib/active_interactor/organizer/base.rb +0 -18
  26. data/lib/active_interactor/organizer/callbacks.rb +0 -275
  27. data/lib/active_interactor/organizer/interactor_interface.rb +0 -127
  28. data/lib/active_interactor/organizer/interactor_interface_collection.rb +0 -62
  29. data/lib/active_interactor/organizer/organize.rb +0 -67
  30. data/lib/active_interactor/organizer/perform.rb +0 -112
  31. data/lib/active_interactor/rails/orm/active_record.rb +0 -5
  32. data/lib/active_interactor/rails/orm/dynamoid.rb +0 -5
  33. data/lib/active_interactor/rails/orm/mongoid.rb +0 -5
  34. data/lib/active_interactor/rails/railtie.rb +0 -21
  35. data/lib/active_interactor/rails.rb +0 -4
  36. data/lib/active_interactor/version.rb +0 -45
  37. data/lib/rails/generators/active_interactor/application_context_generator.rb +0 -21
  38. data/lib/rails/generators/active_interactor/application_interactor_generator.rb +0 -21
  39. data/lib/rails/generators/active_interactor/application_organizer_generator.rb +0 -21
  40. data/lib/rails/generators/active_interactor/base.rb +0 -29
  41. data/lib/rails/generators/active_interactor/generator.rb +0 -21
  42. data/lib/rails/generators/active_interactor/install_generator.rb +0 -16
  43. data/lib/rails/generators/active_interactor.rb +0 -5
  44. data/lib/rails/generators/interactor/context/rspec_generator.rb +0 -17
  45. data/lib/rails/generators/interactor/context/test_unit_generator.rb +0 -17
  46. data/lib/rails/generators/interactor/context_generator.rb +0 -22
  47. data/lib/rails/generators/interactor/generates_context.rb +0 -28
  48. data/lib/rails/generators/interactor/interactor_generator.rb +0 -25
  49. data/lib/rails/generators/interactor/organizer_generator.rb +0 -39
  50. data/lib/rails/generators/interactor/rspec_generator.rb +0 -15
  51. data/lib/rails/generators/interactor/test_unit_generator.rb +0 -15
  52. data/lib/rails/generators/templates/active_interactor.erb +0 -17
  53. data/lib/rails/generators/templates/application_context.rb +0 -4
  54. data/lib/rails/generators/templates/application_interactor.rb +0 -4
  55. data/lib/rails/generators/templates/application_organizer.rb +0 -4
  56. data/lib/rails/generators/templates/context.erb +0 -7
  57. data/lib/rails/generators/templates/context_spec.erb +0 -7
  58. data/lib/rails/generators/templates/context_test_unit.erb +0 -9
  59. data/lib/rails/generators/templates/interactor.erb +0 -15
  60. data/lib/rails/generators/templates/interactor_spec.erb +0 -7
  61. data/lib/rails/generators/templates/interactor_test_unit.erb +0 -9
  62. data/lib/rails/generators/templates/organizer.erb +0 -13
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- # Configurable object methods. Because {Configurable} is a module classes should include {Configurable} rather than
5
- # inherit from it.
6
- #
7
- # @api private
8
- # @author Aaron Allen <hello@aaronmallen.me>
9
- # @since 1.0.0
10
- module Configurable
11
- def self.included(base)
12
- base.class_eval do
13
- extend ClassMethods
14
- end
15
- end
16
-
17
- # Configurable object class methods. Because {ClassMethods} is a module classes should extend {ClassMethods} rather
18
- # than inherit from it.
19
- #
20
- # @api private
21
- # @author Aaron Allen <hello@aaronmallen.me>
22
- # @since 1.0.0
23
- module ClassMethods
24
- # Get or Set the default attributes for a {Configurable} class. This method will create an `attr_accessor` on
25
- # the configurable class as well as set a default value for the attribute.
26
- #
27
- # @param options [Hash{Symbol=>*}, nil] the default options to set on the {Configurable} class
28
- # @return [Hash{Symbol=>*}] the passed options or the set defaults if no options are passed.
29
- def defaults(options = {})
30
- return __defaults if options.empty?
31
-
32
- options.each do |key, value|
33
- __defaults[key.to_sym] = value
34
- send(:attr_accessor, key.to_sym)
35
- end
36
- end
37
-
38
- private
39
-
40
- def __defaults
41
- @__defaults ||= {}
42
- end
43
- end
44
-
45
- # nodoc #
46
- # @private
47
- def initialize(options = {})
48
- self.class.defaults.merge(options).each do |key, value|
49
- instance_variable_set("@#{key}", value)
50
- end
51
- end
52
- end
53
- end
@@ -1,179 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- module Context
5
- # Context attribute methods. Because {Attributes} is a module classes should include {Attributes} rather than
6
- # inherit from it.
7
- #
8
- # @author Aaron Allen <hello@aaronmallen.me>
9
- # @since 0.1.4
10
- module Attributes
11
- # Context attribute class methods. Because {ClassMethods} is a module classes should extend {ClassMethods} rather
12
- # than inherit from it.
13
- #
14
- # @author Aaron Allen <hello@aaronmallen.me>
15
- # @since 0.1.4
16
- module ClassMethods
17
- # Get or set attributes on a {Base context} class
18
- #
19
- # @example Set attributes on a {Base context} class
20
- # class MyContext < ActiveInteractor::Context::Base
21
- # attributes :first_name, :last_name
22
- # end
23
- #
24
- # @example Get attributes defined on a {Base context} class
25
- # MyContext.attributes
26
- # #=> [:first_name, :last_name]
27
- #
28
- # @example Set defaults for attributes on a {Base context} class
29
- # class MyContext < ActiveInteractor::Context::Base
30
- # attributes first_name: { default: -> { 'Aaron' } }, last_name: { default: -> { 'Allen' } }
31
- # end
32
- #
33
- # @return [Array<Symbol>] the defined attributes
34
- def attributes(*attributes)
35
- attributes.compact.uniq.each { |attr| attribute(attr) }
36
-
37
- attribute_names.sort.collect(&:to_sym)
38
- end
39
-
40
- private
41
-
42
- def attribute?(attr_name)
43
- attribute_types.key?(attr_name.to_s)
44
- end
45
- alias has_attribute? attribute?
46
- end
47
-
48
- # Initialize a new instance of {Base}
49
- #
50
- # @param context [Hash, Base, Class] attributes to assign to the {Base context}
51
- # @return [Base] a new instance of {Base}
52
- def initialize(context = {})
53
- merge_errors!(context) if context.respond_to?(:errors)
54
- copy_flags!(context)
55
- copy_called!(context)
56
- context = context_attributes_as_hash(context) || {}
57
- super
58
-
59
- merge_attribute_values(context)
60
- end
61
-
62
- # Returns the value of an attribute
63
- #
64
- # @since 1.0.5
65
- #
66
- # @param name [String, Symbol] the key of the value to be returned
67
- # @returns [*] the attribute value
68
- def [](name)
69
- @table[name.to_sym] || attributes[name.to_sym]
70
- end
71
-
72
- # Sets value of a Hash attribute in context.attributes
73
- #
74
- # @since 1.1.0
75
- #
76
- # @param name [String, Symbol] the key name of the attribute
77
- # @param value [*] the value to be given attribute name
78
- # @returns [*] the attribute value
79
- def []=(name, value)
80
- public_send("#{name}=", value)
81
-
82
- super unless @table.nil?
83
- end
84
-
85
- # Get values defined on the instance of {Base context} whose keys are defined on the {Base context} class'
86
- # {ClassMethods#attributes .attributes}
87
- #
88
- # @example Get attributes defined on an instance of {Base context}
89
- # class MyContext < ActiveInteractor::Context::Base
90
- # attributes :first_name, :last_name
91
- # end
92
- #
93
- # context = MyContext.new(first_name: 'Aaron', last_name: 'Allen', occupation: 'Ruby Nerd')
94
- # #=> <#MyContext first_name='Aaron' last_name='Allen' occupation='Ruby Nerd')
95
- #
96
- # context.attributes
97
- # #=> { first_name: 'Aaron', last_name: 'Allen' }
98
- #
99
- # context.occupation
100
- # #=> 'Ruby Nerd'
101
- #
102
- # @return [Hash{Symbol => *}] the defined attributes and values
103
- def attributes
104
- super.symbolize_keys
105
- end
106
-
107
- # Check if the {Base context} instance has an attribute
108
- #
109
- # @since 1.0.1
110
- #
111
- # @param attr_name [Symbol, String] the name of the attribute to check
112
- # @return [Boolean] whether or not the {Base context} instance has the attribute
113
- def attribute?(attr_name)
114
- @attributes.key?(attr_name.to_s)
115
- end
116
- alias has_attribute? attribute?
117
-
118
- # Merge an instance of {Base context} into the calling {Base context} instance
119
- #
120
- # @since 1.0.0
121
- #
122
- # @example
123
- # context = MyContext.new(first_name: 'Aaron', last_name: 'Allen')
124
- # other_context = MyContext.new(last_name: 'Awesome')
125
- # context.merge!(other_context)
126
- # #=> <#MyContext first_name='Aaron' last_name='Awesome'>
127
- #
128
- # @param context [Class] a {Base context} instance to be merged
129
- # @return [self] the {Base context} instance
130
- def merge!(context)
131
- merge_errors!(context) if context.respond_to?(:errors)
132
- copy_flags!(context)
133
-
134
- merged_context_attributes(context).each_pair do |key, value|
135
- self[key] = value unless value.nil?
136
- end
137
- self
138
- end
139
-
140
- private
141
-
142
- def _called
143
- @_called ||= []
144
- end
145
-
146
- def merged_context_attributes(context)
147
- attrs = {}
148
- attrs.merge!(context.to_h) if context.respond_to?(:to_h)
149
- attrs.merge!(context.attributes.to_h) if context.respond_to?(:attributes)
150
- attrs
151
- end
152
-
153
- def context_attributes_as_hash(context)
154
- return context.to_h if context&.respond_to?(:to_h)
155
- return context.attributes.to_h if context.respond_to?(:attributes)
156
- end
157
-
158
- def copy_called!(context)
159
- value = context.instance_variable_get('@_called') || []
160
- instance_variable_set('@_called', value)
161
- end
162
-
163
- def copy_flags!(context)
164
- %w[_failed _rolled_back].each do |flag|
165
- value = context.instance_variable_get("@#{flag}")
166
- instance_variable_set("@#{flag}", value)
167
- end
168
- end
169
-
170
- def merge_attribute_values(context)
171
- return unless context
172
-
173
- attributes.compact.merge(context).each_pair do |key, value|
174
- self[key] = value
175
- end
176
- end
177
- end
178
- end
179
- end
@@ -1,333 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- module Context
5
- # The base {Base context} class all {Base context} objects should inherit from.
6
- #
7
- # @author Aaron Allen <hello@aaronmallen.me>
8
- # @since 0.1.0
9
- #
10
- # @!method attribute(name, type=Type::Value.new, **options)
11
- # @!scope class
12
- # @since 1.0.1
13
- #
14
- # @example Setting default values on the {Base context} class
15
- # class MyContext < ActiveInteractor::Context::Base
16
- # attribute :first_name, default: -> { 'Aaron' }
17
- # end
18
- #
19
- # MyContext.new
20
- # #=> <#MyContext first_name='Aaron'>
21
- #
22
- # MyContext.new(first_name: 'Bob')
23
- # #=> <#MyContext first_name='Bob'>
24
- #
25
- # @see
26
- # https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html#method-i-attribute
27
- # ActiveModel::Attributes::ClassMethods#attribute
28
- #
29
- #
30
- # @!method attribute_method?(attribute)
31
- # @!scope class
32
- # @since 0.1.0
33
- # @see
34
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-attribute_method-3F
35
- # ActiveModel::Validations::ClassMethods#attribute_method?
36
- #
37
- # @!method attribute_missing(match, *args, &block)
38
- # @!scope class
39
- # @since 1.0.1
40
- # @see
41
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-attribute_missing
42
- # ActiveModel::AttributeMethods#attribute_missing
43
- #
44
- # @!method attribute_names
45
- # @!scope class
46
- # @since 1.0.1
47
- # @see
48
- # https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html#method-i-attribute_names
49
- # ActiveModel::Attributes::ClassMethods#attribute_names
50
- #
51
- # @!method clear_validators!(attribute)
52
- # @!scope class
53
- # @since 0.1.0
54
- # @see
55
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-clear_validators-21
56
- # ActiveModel::Validations::ClassMethods#clear_validators!
57
- #
58
- # @!method method_missing(method, *args, &block)
59
- # @scope class
60
- # @since 1.0.1
61
- # @see
62
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-method_missing
63
- # ActiveModel::AttributeMethods#method_missing
64
- #
65
- # @!method respond_to?(method, include_private_methods = false)
66
- # @scope class
67
- # @since 1.0.1
68
- # @see
69
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-respond_to-3F
70
- # ActiveModel::AttributeMethods#respond_to?
71
- #
72
- # @!method respond_to_without_attributes?(method, include_private_methods = false)
73
- # @scope class
74
- # @since 1.0.1
75
- # @see
76
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-respond_to_without_attributes-3F
77
- # ActiveModel::AttributeMethods#respond_to_without_attributes?
78
- #
79
- # @!method validate(*args, &block)
80
- # @!scope class
81
- # @since 0.1.0
82
- # @see
83
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate
84
- # ActiveModel::Validations::ClassMethods#validate
85
- #
86
- # @!method validates(*attributes)
87
- # @!scope class
88
- # @since 0.1.0
89
- # @see
90
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates
91
- # ActiveModel::Validations::ClassMethods#validates
92
- #
93
- # @!method validates!(*attributes)
94
- # @!scope class
95
- # @since 0.1.0
96
- # @see
97
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates-21
98
- # ActiveModel::Validations::ClassMethods#validates!
99
- #
100
- # @!method validates_absence_of(*attr_names)
101
- # @!scope class
102
- # @since 0.1.0
103
- # @see
104
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_absence_of
105
- # ActiveModel::Validations::HelperMethods#validates_absence_of
106
- #
107
- # @!method validates_acceptance_of(*attr_names)
108
- # @!scope class
109
- # @since 0.1.0
110
- # @see
111
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_acceptance_of
112
- # ActiveModel::Validations::HelperMethods#validates_acceptance_of
113
- #
114
- # @!method validates_confirmation_of(*attr_names)
115
- # @!scope class
116
- # @since 0.1.0
117
- # @see
118
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_confirmation_of
119
- # ActiveModel::Validations::HelperMethods#validates_confirmation_of
120
- #
121
- # @!method validates_each(*attr_names, &block)
122
- # @!scope class
123
- # @since 0.1.0
124
- # @see
125
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates_each
126
- # ActiveModel::Validations::ClassMethods#validates_each
127
- #
128
- # @!method validates_exclusion_of(*attr_names)
129
- # @!scope class
130
- # @since 0.1.0
131
- # @see
132
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_exclusion_of
133
- # ActiveModel::Validations::HelperMethods#validates_exclusion_of
134
- #
135
- # @!method validates_format_of(*attr_names)
136
- # @!scope class
137
- # @since 0.1.0
138
- # @see
139
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_format_of
140
- # ActiveModel::Validations::HelperMethods#validates_format_of
141
- #
142
- # @!method validates_inclusion_of(*attr_names)
143
- # @!scope class
144
- # @since 0.1.0
145
- # @see
146
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_inclusion_of
147
- # ActiveModel::Validations::HelperMethods#validates_inclusion_of
148
- #
149
- # @!method validates_length_of(*attr_names)
150
- # @!scope class
151
- # @since 0.1.0
152
- # @see
153
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_length_of
154
- # ActiveModel::Validations::HelperMethods#validates_length_of
155
- #
156
- # @!method validates_numericality_of(*attr_names)
157
- # @!scope class
158
- # @since 0.1.0
159
- # @see
160
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of
161
- # ActiveModel::Validations::HelperMethods#validates_numericality_of
162
- #
163
- # @!method validates_presence_of(*attr_names)
164
- # @!scope class
165
- # @since 0.1.0
166
- # @see
167
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_presence_of
168
- # ActiveModel::Validations::HelperMethods#validates_presence_of
169
- #
170
- # @!method validates_size_of(*attr_names)
171
- # @!scope class
172
- # @since 0.1.0
173
- # @see
174
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_size_of
175
- # ActiveModel::Validations::HelperMethods#validates_size_of
176
- #
177
- # @!method validates_with(*args, &block)
178
- # @!scope class
179
- # @since 0.1.0
180
- # @see
181
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates_with
182
- # ActiveModel::Validations::ClassMethods#validates_with
183
- #
184
- # @!method validators
185
- # @!scope class
186
- # @since 0.1.0
187
- # @see
188
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validators
189
- # ActiveModel::Validations::ClassMethods#validators
190
- #
191
- # @!method validators_on(*attributes)
192
- # @!scope class
193
- # @since 0.1.0
194
- # @see
195
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validators_on
196
- # ActiveModel::Validations::ClassMethods#validators_on
197
- #
198
- # @!method attribute_missing(match, *args, &block)
199
- # @since 1.0.1
200
- # @see
201
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-attribute_missing
202
- # ActiveModel::AttributeMethods#attribute_missing
203
- #
204
- # @!method attribute_names
205
- # @since 1.0.1
206
- # @see
207
- # https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html#method-i-attribute_names
208
- # ActiveModel::Attributes::ClassMethods#attribute_names
209
- #
210
- # @!method errors
211
- # @since 0.1.0
212
- # @see
213
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-errors
214
- # ActiveModel::Validations#errors
215
- #
216
- # @!method invalid?(context = nil)
217
- # @since 0.1.0
218
- # @see
219
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-invalid-3F
220
- # ActiveModel::Validations#invalid?
221
- #
222
- # @!method method_missing(method, *args, &block)
223
- # @since 1.0.1
224
- # @see
225
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-method_missing
226
- # ActiveModel::AttributeMethods#method_missing
227
- #
228
- # @!method respond_to?(method, include_private_methods = false)
229
- # @since 1.0.1
230
- # @see
231
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-respond_to-3F
232
- # ActiveModel::AttributeMethods#respond_to?
233
- #
234
- # @!method respond_to_without_attributes?(method, include_private_methods = false)
235
- # @since 1.0.1
236
- # @see
237
- # https://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-respond_to_without_attributes-3F
238
- # ActiveModel::AttributeMethods#respond_to_without_attributes?
239
- #
240
- # @!method valid?(context = nil)
241
- # @since 0.1.0
242
- # @see
243
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-valid-3F
244
- # ActiveModel::Validations#valid?
245
- #
246
- # @!method validate(context = nil)
247
- # @since 0.1.0
248
- # @see
249
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-validate
250
- # ActiveModel::Validations#validate
251
- #
252
- # @!method validate!(context = nil)
253
- # @since 0.1.0
254
- # @see
255
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-validate-21
256
- # ActiveModel::Validations#validate!
257
- #
258
- # @!method validates_absence_of(*attr_names)
259
- # @since 0.1.0
260
- # @see
261
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_absence_of
262
- # ActiveModel::Validations::HelperMethods#validates_absence_of
263
- #
264
- # @!method validates_acceptance_of(*attr_names)
265
- # @since 0.1.0
266
- # @see
267
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_acceptance_of
268
- # ActiveModel::Validations::HelperMethods#validates_acceptance_of
269
- #
270
- # @!method validates_confirmation_of(*attr_names)
271
- # @since 0.1.0
272
- # @see
273
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_confirmation_of
274
- # ActiveModel::Validations::HelperMethods#validates_confirmation_of
275
- #
276
- # @!method validates_exclusion_of(*attr_names)
277
- # @since 0.1.0
278
- # @see
279
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_exclusion_of
280
- # ActiveModel::Validations::HelperMethods#validates_exclusion_of
281
- #
282
- # @!method validates_format_of(*attr_names)
283
- # @since 0.1.0
284
- # @see
285
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_format_of
286
- # ActiveModel::Validations::HelperMethods#validates_format_of
287
- #
288
- # @!method validates_inclusion_of(*attr_names)
289
- # @since 0.1.0
290
- # @see
291
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_inclusion_of
292
- # ActiveModel::Validations::HelperMethods#validates_inclusion_of
293
- #
294
- # @!method validates_length_of(*attr_names)
295
- # @since 0.1.0
296
- # @see
297
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_length_of
298
- # ActiveModel::Validations::HelperMethods#validates_length_of
299
- #
300
- # @!method validates_numericality_of(*attr_names)
301
- # @since 0.1.0
302
- # @see
303
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of
304
- # ActiveModel::Validations::HelperMethods#validates_numericality_of
305
- #
306
- # @!method validates_presence_of(*attr_names)
307
- # @since 0.1.0
308
- # @see
309
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_presence_of
310
- # ActiveModel::Validations::HelperMethods#validates_presence_of
311
- #
312
- # @!method validates_size_of(*attr_names)
313
- # @since 0.1.0
314
- # @see
315
- # https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_size_of
316
- # ActiveModel::Validations::HelperMethods#validates_size_of
317
- #
318
- # @!method validates_with(*args, &block)
319
- # @since 0.1.0
320
- # @see
321
- # https://api.rubyonrails.org/classes/ActiveModel/Validations.html#method-i-validates_with
322
- # ActiveModel::Validations#validates_with
323
- class Base < OpenStruct
324
- extend ActiveInteractor::Context::Attributes::ClassMethods
325
-
326
- include ActiveModel::Attributes
327
- include ActiveModel::Validations
328
- include ActiveInteractor::Context::Attributes
329
- include ActiveInteractor::Context::Errors
330
- include ActiveInteractor::Context::Status
331
- end
332
- end
333
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- module Context
5
- # Context error methods. Because {Errors} is a module classes should include {Errors} rather than
6
- # inherit from it.
7
- #
8
- # @api private
9
- # @author Aaron Allen <hello@aaronmallen.me>
10
- # @since 1.0.3
11
- module Errors
12
- # Generic errors generated outside of validation.
13
- #
14
- # @return [ActiveModel::Errors] an instance of `ActiveModel::Errors`
15
- def failure_errors
16
- @failure_errors ||= ActiveModel::Errors.new(self)
17
- end
18
-
19
- private
20
-
21
- def add_errors(errors)
22
- errors.each do |error|
23
- if self.errors.respond_to?(:import)
24
- self.errors.import(error)
25
- else
26
- self.errors.add(error[0], error[1])
27
- end
28
- end
29
- end
30
-
31
- def clear_all_errors
32
- errors.clear
33
- failure_errors.clear
34
- end
35
-
36
- def handle_errors(errors)
37
- if errors.is_a?(String)
38
- failure_errors.add(:context, errors)
39
- else
40
- failure_errors.merge!(errors)
41
- end
42
- end
43
-
44
- def merge_errors!(other)
45
- errors.merge!(other.errors)
46
- failure_errors.merge!(other.errors)
47
- failure_errors.merge!(other.failure_errors)
48
- end
49
-
50
- def resolve_errors
51
- all_errors = (failure_errors.uniq + errors.uniq).compact.uniq
52
- clear_all_errors
53
- add_errors(all_errors)
54
- end
55
- end
56
- end
57
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveInteractor
4
- module Context
5
- # Find or create {Base context} classes for a given {ActiveInteractor::Base interactor}
6
- #
7
- # @api private
8
- # @author Aaron Allen <hello@aaronmallen>
9
- # @since 1.0.0
10
- module Loader
11
- # ActiveInteractor base classes
12
- # @return [Array<Const>]
13
- BASE_CLASSES = [ActiveInteractor::Base, ActiveInteractor::Organizer::Base].freeze
14
- # The {ActiveInteractor::Context::Base} class
15
- # @return [Const]
16
- BASE_CONTEXT = ActiveInteractor::Context::Base
17
-
18
- # Create a {Base context} class for a given {ActiveInteractor::Base interactor}
19
- #
20
- # @param context_class_name [Symbol, String] the class name of the
21
- # {Base context} class to create
22
- # @param interactor_class [Const] an {ActiveInteractor::Base interactor} class
23
- # @return [Const] a class that inherits from {Base}
24
- def self.create(context_class_name, interactor_class)
25
- interactor_class.const_set(context_class_name.to_s.camelize, Class.new(BASE_CONTEXT))
26
- end
27
-
28
- # Find or create a {Base context} class for a given {ActiveInteractor::Base interactor}. If a class exists
29
- # following the pattern of `InteractorNameContext` or `InteractorName::Context` then that class will be returned
30
- # otherwise a new class will be created with the pattern `InteractorName::Context`.
31
- #
32
- # @param interactor_class [Const] an {ActiveInteractor::Base interactor} class
33
- # @return [Const] a class that inherits from {Base}
34
- def self.find_or_create(interactor_class)
35
- return BASE_CONTEXT if BASE_CLASSES.include?(interactor_class)
36
-
37
- klass = possible_classes(interactor_class).first
38
- klass || create('Context', interactor_class)
39
- end
40
-
41
- def self.possible_classes(interactor_class)
42
- ["#{interactor_class.name}::Context", "#{interactor_class.name}Context"]
43
- .map(&:safe_constantize)
44
- .compact
45
- .reject { |klass| klass&.name&.include?('ActiveInteractor') }
46
- end
47
- private_class_method :possible_classes
48
- end
49
- end
50
- end