activeinteractor 2.0.0.alpha.2.3.5 → 2.0.0.alpha.3.0.0
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 +4 -4
- data/lib/active_interactor/context/base.rb +6 -1
- data/lib/active_interactor/context/result.rb +12 -1
- data/lib/active_interactor/interactor/context_methods.rb +6 -2
- data/lib/active_interactor/result.rb +2 -2
- data/lib/active_interactor.rb +5 -0
- metadata +5 -6
- data/lib/active_interactor/base.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1c2ce9c50cbde2cea19a341cec6e19cbaff9bf4aa616956d8ced13e60f415d
|
4
|
+
data.tar.gz: 3e614d932dd30f5cfd6d5b823fa12a586ae4cabb7a27da510a098ab08e0f2a40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e65e3fca3155ed70b3cffa301597f451a1219c6feca2ca769e3aeab9439ad3df61772d6214d396a78a6631c3506dbed5bfcce2d144f6813247c12559e6eeaf4
|
7
|
+
data.tar.gz: 38ae85a08ce12b0321041179501bb8c7941acb8a56a6c475269630da36d81b8ed3064759fd460c7e3407e787d428c20591d3e6ff04613880df8f49065e8553de
|
@@ -3,17 +3,22 @@
|
|
3
3
|
module ActiveInteractor
|
4
4
|
module Context
|
5
5
|
class Base
|
6
|
+
include ActiveModel::Validations
|
6
7
|
include ActiveModelErrorMethods
|
7
8
|
include AttributeRegistration
|
8
9
|
include AttributeAssignment
|
9
10
|
include Type::DeclerationMethods
|
10
11
|
|
12
|
+
validate :validate_attributes!
|
13
|
+
|
11
14
|
def initialize(attributes = {})
|
12
15
|
super
|
13
16
|
@errors = ActiveModel::Errors.new(self)
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
protected
|
20
|
+
|
21
|
+
def validate_attributes!
|
17
22
|
attribute_set.attributes.each do |attribute|
|
18
23
|
attribute.validate!
|
19
24
|
attribute.error_messages.each { |message| errors.add(attribute.name, message) }
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module ActiveInteractor
|
4
4
|
module Context
|
5
5
|
class Result
|
6
|
+
delegate :[], :as_json, :to_json, to: :to_hash
|
7
|
+
|
6
8
|
def self.register_owner(owner)
|
7
9
|
owner.const_set(:ResultContext, Class.new(self))
|
8
10
|
end
|
@@ -13,8 +15,17 @@ module ActiveInteractor
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def initialize(attributes = {})
|
16
|
-
attributes
|
18
|
+
@attributes = {}
|
19
|
+
attributes.each_pair do |key, value|
|
20
|
+
instance_variable_set(:"@#{key}", value)
|
21
|
+
@attributes[key] = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@attributes.with_indifferent_access
|
17
27
|
end
|
28
|
+
alias to_h to_hash
|
18
29
|
end
|
19
30
|
end
|
20
31
|
end
|
@@ -8,6 +8,10 @@ module ActiveInteractor
|
|
8
8
|
module ClassMethods
|
9
9
|
delegate :argument, :argument_names, :arguments, to: :input_context_class
|
10
10
|
delegate :returns, :field_names, :fields, to: :output_context_class
|
11
|
+
delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :input_context_class, prefix: :input)
|
12
|
+
delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :input_context_class, prefix: :input)
|
13
|
+
delegate(*ActiveModel::Validations::ClassMethods.instance_methods, to: :output_context_class, prefix: :output)
|
14
|
+
delegate(*ActiveModel::Validations::HelperMethods.instance_methods, to: :output_context_class, prefix: :output)
|
11
15
|
|
12
16
|
def input_context_class
|
13
17
|
@input_context_class ||= const_set(:InputContext, Class.new(Context::Input))
|
@@ -57,7 +61,7 @@ module ActiveInteractor
|
|
57
61
|
|
58
62
|
def generate_and_validate_output_context!
|
59
63
|
@output = self.class.output_context_class.new(context.attributes)
|
60
|
-
@output.
|
64
|
+
@output.valid?
|
61
65
|
return if @output.errors.empty?
|
62
66
|
|
63
67
|
raise Error, Result.failure(errors: @output.errors, status: Result::STATUS[:failed_at_output])
|
@@ -69,7 +73,7 @@ module ActiveInteractor
|
|
69
73
|
|
70
74
|
def validate_input_and_generate_runtime_context!
|
71
75
|
@input = self.class.input_context_class.new(@raw_input)
|
72
|
-
@input.
|
76
|
+
@input.valid?
|
73
77
|
return (@context = self.class.runtime_context_class.new(@raw_input)) if @input.errors.empty?
|
74
78
|
|
75
79
|
raise Error, Result.failure(errors: @input.errors, status: Result::STATUS[:failed_at_input])
|
@@ -90,7 +90,7 @@ module ActiveInteractor
|
|
90
90
|
when String
|
91
91
|
{ generic: [errors] }
|
92
92
|
when ActiveModel::Errors
|
93
|
-
errors.
|
93
|
+
errors.to_hash
|
94
94
|
else
|
95
95
|
errors
|
96
96
|
end
|
@@ -127,7 +127,7 @@ module ActiveInteractor
|
|
127
127
|
|
128
128
|
# @private
|
129
129
|
def read_attribute_for_validation(attribute_name)
|
130
|
-
data
|
130
|
+
data&.send(attribute_name.to_sym)
|
131
131
|
end
|
132
132
|
|
133
133
|
# Whether or not the {ActiveInteractor::Interactor::Base result} is a success
|
data/lib/active_interactor.rb
CHANGED
@@ -28,6 +28,11 @@ require_relative 'active_interactor/errors'
|
|
28
28
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
29
29
|
# THE SOFTWARE.
|
30
30
|
#
|
31
|
+
# {https://activeinteractor.org ActiveInteractor} is An implementation of the Command
|
32
|
+
# Pattern for Ruby with ActiveModel::Validations inspired by the interactor gem.
|
33
|
+
# It has features like rich support for attributes, callbacks, and validations, and
|
34
|
+
# thread safe performance methods.
|
35
|
+
#
|
31
36
|
# {file:CHANGELOG.md Changelog}
|
32
37
|
#
|
33
38
|
# {file:HUMANS.md Acknowledgements}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeinteractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.alpha.
|
4
|
+
version: 2.0.0.alpha.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- README.md
|
65
65
|
- lib/active_interactor.rb
|
66
66
|
- lib/active_interactor/active_model_error_methods.rb
|
67
|
-
- lib/active_interactor/base.rb
|
68
67
|
- lib/active_interactor/context.rb
|
69
68
|
- lib/active_interactor/context/attribute.rb
|
70
69
|
- lib/active_interactor/context/attribute_assignment.rb
|
@@ -93,10 +92,10 @@ licenses:
|
|
93
92
|
- MIT
|
94
93
|
metadata:
|
95
94
|
bug_tracker_uri: https://github.com/activeinteractor/activeinteractor/issues
|
96
|
-
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.
|
95
|
+
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.3.0.0/CHANGELOG.md
|
97
96
|
homepage_uri: https://activeinteractor.org
|
98
|
-
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.
|
99
|
-
documentation_uri: https://activeinteractor.org/api/activeinteractor/v2.0.0-alpha.
|
97
|
+
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.3.0.0
|
98
|
+
documentation_uri: https://activeinteractor.org/api/activeinteractor/v2.0.0-alpha.3.0.0
|
100
99
|
wiki_uri: https://github.com/activeinteractor/activeinteractor/wiki
|
101
100
|
rubygems_mfa_required: 'true'
|
102
101
|
post_install_message:
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveInteractor
|
4
|
-
# The Main interface for ActiveInteractor
|
5
|
-
#
|
6
|
-
# @deprecated will be removed in version 2.0.0-alpha.3.0.0
|
7
|
-
# use {ActiveInteractor::Interactor::Base} instead
|
8
|
-
class Base < ActiveInteractor::Interactor::Base; end
|
9
|
-
end
|