activeinteractor 2.0.0.alpha.2.3.4 → 2.0.0.alpha.3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/active_interactor/context/base.rb +6 -1
- data/lib/active_interactor/context/result.rb +12 -1
- data/lib/active_interactor/interactor/base.rb +1 -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 +8 -9
- 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
|
data/README.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
[![Version](https://img.shields.io/gem/v/activeinteractor.svg?logo=ruby)](https://rubygems.org/gems/activeinteractor)
|
4
4
|
[![Build](https://github.com/activeinteractor/activeinteractor/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/activeinteractor/activeinteractor/actions/workflows/build.yml)
|
5
|
+
[![Docs](https://img.shields.io/badge/docs-blue)](https://activeinteractor.org/)
|
5
6
|
[![License](https://img.shields.io/github/license/activeinteractor/activeinteractor.svg?maxAge=300)](https://github.com/activeinteractor/activeinteractor/blob/main/LICENSE)
|
6
7
|
|
8
|
+
![ActiveInteractor Logo](https://activeinteractor.org/assets/images/logo.png)
|
9
|
+
|
7
10
|
## DISCLAIMER
|
8
11
|
|
9
12
|
This project is a work in progress. Go [here](https://github.com/aaronmallen/activeinteractor) for information on the current version of ActiveInteractor.
|
@@ -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
|
@@ -88,15 +87,15 @@ files:
|
|
88
87
|
- lib/active_interactor/type/list.rb
|
89
88
|
- lib/active_interactor/type/union.rb
|
90
89
|
- sig/active_interactor.rbs
|
91
|
-
homepage: https://
|
90
|
+
homepage: https://activeinteractor.org
|
92
91
|
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.
|
97
|
-
homepage_uri: https://
|
98
|
-
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.
|
99
|
-
documentation_uri: https://api
|
95
|
+
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.3.0.0/CHANGELOG.md
|
96
|
+
homepage_uri: https://activeinteractor.org
|
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:
|
@@ -114,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
113
|
- !ruby/object:Gem::Version
|
115
114
|
version: 1.3.1
|
116
115
|
requirements: []
|
117
|
-
rubygems_version: 3.4.
|
116
|
+
rubygems_version: 3.4.21
|
118
117
|
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: Ruby interactors with ActiveModel::Validations
|
@@ -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
|