activeinteractor 2.0.0.alpha.2.3.3 → 2.0.0.alpha.2.3.4
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/active_model_error_methods.rb +2 -0
- data/lib/active_interactor/base.rb +5 -3
- data/lib/active_interactor/context.rb +1 -0
- data/lib/active_interactor/errors.rb +13 -0
- data/lib/active_interactor/interactor/base.rb +1 -0
- data/lib/active_interactor/interactor.rb +1 -0
- data/lib/active_interactor/result.rb +94 -1
- data/lib/active_interactor/type.rb +1 -0
- data/lib/active_interactor.rb +30 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d75851d221fb7d266849601c5eef65939edfb615419818393ca9ea9b165a4279
|
4
|
+
data.tar.gz: '08f62a487d21f34df03f63b0dc112010df68fbb0a6aa6f3931d972eb0dbaed36'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 533fa79817a6d0598c1dac316da54f19ac5e96067ede7f65869f26a2c84b5481a134fab044ed947061d6a19f9021c829dc428456e4cb25483ea276b44c5ba6a7
|
7
|
+
data.tar.gz: 9efe50f237b0bd204678158dd9ba27482b93e640193f8c3f3cbd71025d2b46fb1490bbb19bf25b31adeecdb02298947dbf41a1bd7cb03659c3bc1871faf1605e
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveInteractor
|
4
|
+
# @private
|
4
5
|
module ActiveModelErrorMethods
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
|
7
8
|
attr_reader :errors
|
8
9
|
|
10
|
+
# @private
|
9
11
|
module ClassMethods
|
10
12
|
def human_attribute_name(attribute, _options = {})
|
11
13
|
attribute.respond_to?(:to_s) ? attribute.to_s.humanize : attribute
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveInteractor
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
7
9
|
end
|
@@ -1,9 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveInteractor
|
4
|
+
# Raised when an interactor fails
|
5
|
+
#
|
6
|
+
# @!attribute [r] result
|
7
|
+
# @return [ActiveInteractor::Result] An instance of {ActiveInteractor::Result} for the
|
8
|
+
# {ActiveInteractor::Interactor::Base interactor} that failed
|
4
9
|
class Error < StandardError
|
5
10
|
attr_reader :result
|
6
11
|
|
12
|
+
# Create a new instance of {ActiveInteractor::Error}
|
13
|
+
#
|
14
|
+
# @param result [ActiveInteractor::Result] An instance of {ActiveInteractor::Result} for the
|
15
|
+
# {ActiveInteractor::Interactor::Base interactor} that failed
|
16
|
+
# @param message [String] The error message
|
17
|
+
#
|
18
|
+
# @private
|
19
|
+
# @return [ActiveInteractor::Error]
|
7
20
|
def initialize(result, message = nil)
|
8
21
|
@result = result
|
9
22
|
super(message)
|
@@ -1,11 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveInteractor
|
4
|
+
# The object returned by an {ActiveInteractor::Interactor::Base interactor}
|
5
|
+
#
|
6
|
+
# @!attribute [r] data
|
7
|
+
#
|
8
|
+
# @example Given an {ActiveInteractor::Interactor::Base interactor} that creates an ActiveRecord User
|
9
|
+
# class CreateUser < ActiveInteractor::Interactor::Base
|
10
|
+
# argument :login, String, 'The login for the User', required: true
|
11
|
+
# argument :password, String, 'The password for the User', required: true
|
12
|
+
# argument :password_confirmation, String, 'The password confirmation for the user', required: true
|
13
|
+
#
|
14
|
+
# returns :user, User, 'The created User', required: true
|
15
|
+
#
|
16
|
+
# def interact
|
17
|
+
# context.user = User.new(context)
|
18
|
+
# fail!(context.user.errors) unless context.user.save
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'password')
|
23
|
+
# result.data.user
|
24
|
+
#
|
25
|
+
# #=> <# User @login='johndoe'>
|
26
|
+
#
|
27
|
+
# @return [ActiveInteractor::Context::Result] the data returned by the
|
28
|
+
# {ActiveInteractor::Interactor::Base interactor}
|
29
|
+
#
|
30
|
+
# @!attribute [r] errors
|
31
|
+
# @return [ActiveModel::Errors] the errors returned by the
|
32
|
+
# {ActiveInteractor::Interactor::Base interactor}
|
33
|
+
# @see https://github.com/rails/rails/blob/main/activemodel/lib/active_model/errors.rb ActiveModel::Errors
|
4
34
|
class Result
|
5
35
|
include ActiveModelErrorMethods
|
6
36
|
|
37
|
+
# @!method to_json
|
38
|
+
# The {ActiveInteractor::Interactor::Base result} as a Hash
|
39
|
+
#
|
40
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} succeeds
|
41
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'password')
|
42
|
+
# result.to_hash
|
43
|
+
#
|
44
|
+
# #=> { :success => true, :errors => {}, :data => { :login => 'johndoe' } }
|
45
|
+
#
|
46
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} fails
|
47
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'notpassword')
|
48
|
+
# result.to_hash
|
49
|
+
#
|
50
|
+
# #=> {
|
51
|
+
# #=> :success => false,
|
52
|
+
# #=> :errors => { :password_confirmation => ["doesn't match Password"] },
|
53
|
+
# #=> :data => { :login => 'johndoe' }
|
54
|
+
# #=> }
|
55
|
+
#
|
56
|
+
# @deprecated will be removed in version 2.0.0-alpha.3.0.0
|
57
|
+
# use {#to_hash} instead
|
58
|
+
# @return [Hash {Symbol => Boolean, Hash}]
|
7
59
|
delegate :to_json, to: :to_hash
|
8
60
|
|
61
|
+
# @private
|
9
62
|
STATUS = {
|
10
63
|
success: 0,
|
11
64
|
failed_at_input: 1,
|
@@ -16,10 +69,12 @@ module ActiveInteractor
|
|
16
69
|
attr_reader :data
|
17
70
|
|
18
71
|
class << self
|
72
|
+
# @private
|
19
73
|
def success(data: {})
|
20
74
|
new(status: STATUS[:success], data: data)
|
21
75
|
end
|
22
76
|
|
77
|
+
# @private
|
23
78
|
def failure(data: {}, errors: {}, status: STATUS[:failed_at_runtime])
|
24
79
|
result = new(status: status, data: data)
|
25
80
|
parse_errors(errors).each_pair do |attribute, messages|
|
@@ -43,27 +98,65 @@ module ActiveInteractor
|
|
43
98
|
end
|
44
99
|
|
45
100
|
private_class_method :new
|
46
|
-
|
101
|
+
# @private
|
47
102
|
def initialize(status:, data: {})
|
48
103
|
@status = status
|
49
104
|
@data = data
|
50
105
|
@errors = ActiveModel::Errors.new(self)
|
51
106
|
end
|
52
107
|
|
108
|
+
# Whether or not the {ActiveInteractor::Interactor::Base result} is a failure
|
109
|
+
#
|
110
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} fails
|
111
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'notpassword')
|
112
|
+
# result.failure?
|
113
|
+
#
|
114
|
+
# #=> true
|
115
|
+
#
|
116
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} succeeds
|
117
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'password')
|
118
|
+
# result.failure?
|
119
|
+
#
|
120
|
+
# #=> false
|
121
|
+
#
|
122
|
+
# @return [Boolean]
|
53
123
|
def failure?
|
54
124
|
!success?
|
55
125
|
end
|
56
126
|
alias failed? failure?
|
57
127
|
|
128
|
+
# @private
|
58
129
|
def read_attribute_for_validation(attribute_name)
|
59
130
|
data.send(attribute_name.to_sym)
|
60
131
|
end
|
61
132
|
|
133
|
+
# Whether or not the {ActiveInteractor::Interactor::Base result} is a success
|
134
|
+
#
|
135
|
+
# @return [Boolean]
|
62
136
|
def success?
|
63
137
|
@status == STATUS[:success]
|
64
138
|
end
|
65
139
|
alias successful? success?
|
66
140
|
|
141
|
+
# The {ActiveInteractor::Interactor::Base result} as a Hash
|
142
|
+
#
|
143
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} succeeds
|
144
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'password')
|
145
|
+
# result.to_hash
|
146
|
+
#
|
147
|
+
# #=> { :success => true, :errors => {}, :data => { :login => 'johndoe' } }
|
148
|
+
#
|
149
|
+
# @example When an {ActiveInteractor::Interactor::Base interactor} fails
|
150
|
+
# result = CreateUser.perform(login: 'johndoe', password: 'password', password_confirmation: 'notpassword')
|
151
|
+
# result.to_hash
|
152
|
+
#
|
153
|
+
# #=> {
|
154
|
+
# #=> :success => false,
|
155
|
+
# #=> :errors => { :password_confirmation => ["doesn't match Password"] },
|
156
|
+
# #=> :data => { :login => 'johndoe' }
|
157
|
+
# #=> }
|
158
|
+
#
|
159
|
+
# @return [Hash {Symbol => Boolean, Hash}]
|
67
160
|
def to_hash
|
68
161
|
{
|
69
162
|
success: success?,
|
data/lib/active_interactor.rb
CHANGED
@@ -6,6 +6,36 @@ require 'active_support/core_ext'
|
|
6
6
|
|
7
7
|
require_relative 'active_interactor/errors'
|
8
8
|
|
9
|
+
# ## License
|
10
|
+
#
|
11
|
+
# Copyright (c) 2023 Aaron Allen
|
12
|
+
#
|
13
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
+
# of this software and associated documentation files (the "Software"), to deal
|
15
|
+
# in the Software without restriction, including without limitation the rights
|
16
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
+
# copies of the Software, and to permit persons to whom the Software is
|
18
|
+
# furnished to do so, subject to the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be included in
|
21
|
+
# all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
29
|
+
# THE SOFTWARE.
|
30
|
+
#
|
31
|
+
# {file:CHANGELOG.md Changelog}
|
32
|
+
#
|
33
|
+
# {file:HUMANS.md Acknowledgements}
|
34
|
+
#
|
35
|
+
# {file:SECURITY.md Security Policy}
|
36
|
+
#
|
37
|
+
# @author {hello@aaronmallen.me Aaron Allen}
|
38
|
+
|
9
39
|
module ActiveInteractor
|
10
40
|
extend ActiveSupport::Autoload
|
11
41
|
|
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.2.3.
|
4
|
+
version: 2.0.0.alpha.2.3.4
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -93,9 +93,10 @@ licenses:
|
|
93
93
|
- MIT
|
94
94
|
metadata:
|
95
95
|
bug_tracker_uri: https://github.com/activeinteractor/activeinteractor/issues
|
96
|
-
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.2.3.
|
96
|
+
changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.2.3.4/CHANGELOG.md
|
97
97
|
homepage_uri: https://github.com/activeinteractor/activeinteractor
|
98
|
-
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.2.3.
|
98
|
+
source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.2.3.4
|
99
|
+
documentation_uri: https://api.activeinteractor.io
|
99
100
|
wiki_uri: https://github.com/activeinteractor/activeinteractor/wiki
|
100
101
|
rubygems_mfa_required: 'true'
|
101
102
|
post_install_message:
|