Class: ActiveInteractor::Interactor::Base
Overview
The Base Class inherited by all Interactors
Constant Summary
Type::DeclerationMethods::Boolean
Class Method Summary
collapse
Instance Method Summary
collapse
any, list, union, untyped
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
170
171
172
|
# File 'lib/active_interactor/interactor/base.rb', line 170
def initialize(options = {})
@options = Options.new(options.deep_dup)
end
|
Class Method Details
.accepts_arguments_matching(set_input_context_class) ⇒ Object
Also known as:
input_context, input_type
22
23
24
|
# File 'lib/active_interactor/interactor/base.rb', line 22
def accepts_arguments_matching(set_input_context_class)
@input_context_class = set_input_context_class
end
|
.after_fail ⇒ Object
28
29
30
|
# File 'lib/active_interactor/interactor/base.rb', line 28
def after_fail(...)
set_callback(:fail, :after, ...)
end
|
.after_input_context_create ⇒ Object
32
33
34
|
# File 'lib/active_interactor/interactor/base.rb', line 32
def after_input_context_create(...)
set_callback(:input_context_create, :after, ...)
end
|
.after_input_context_validation ⇒ Object
36
37
38
|
# File 'lib/active_interactor/interactor/base.rb', line 36
def after_input_context_validation(...)
set_callback(:input_context_validation, :after, ...)
end
|
.after_output_context_create ⇒ Object
40
41
42
|
# File 'lib/active_interactor/interactor/base.rb', line 40
def after_output_context_create(...)
set_callback(:output_context_create, :after, ...)
end
|
.after_output_context_validation ⇒ Object
44
45
46
|
# File 'lib/active_interactor/interactor/base.rb', line 44
def after_output_context_validation(...)
set_callback(:output_context_validation, :after, ...)
end
|
48
49
50
|
# File 'lib/active_interactor/interactor/base.rb', line 48
def after_perform(...)
set_callback(:perform, :after, ...)
end
|
.after_rollback ⇒ Object
52
53
54
|
# File 'lib/active_interactor/interactor/base.rb', line 52
def after_rollback(...)
set_callback(:rollback, :after, ...)
end
|
.after_runtime_context_create ⇒ Object
56
57
58
|
# File 'lib/active_interactor/interactor/base.rb', line 56
def after_runtime_context_create(...)
set_callback(:runtime_context_create, :after, ...)
end
|
.around_fail ⇒ Object
60
61
62
|
# File 'lib/active_interactor/interactor/base.rb', line 60
def around_fail(...)
set_callback(:fail, :around, ...)
end
|
.around_input_context_create ⇒ Object
64
65
66
|
# File 'lib/active_interactor/interactor/base.rb', line 64
def around_input_context_create(...)
set_callback(:input_context_create, :around, ...)
end
|
.around_input_context_validation ⇒ Object
68
69
70
|
# File 'lib/active_interactor/interactor/base.rb', line 68
def around_input_context_validation(...)
set_callback(:input_context_validation, :around, ...)
end
|
.around_output_context_create ⇒ Object
72
73
74
|
# File 'lib/active_interactor/interactor/base.rb', line 72
def around_output_context_create(...)
set_callback(:output_context_create, :around, ...)
end
|
.around_output_context_validation ⇒ Object
76
77
78
|
# File 'lib/active_interactor/interactor/base.rb', line 76
def around_output_context_validation(...)
set_callback(:output_context_validation, :around, ...)
end
|
80
81
82
|
# File 'lib/active_interactor/interactor/base.rb', line 80
def around_perform(...)
set_callback(:perform, :around, ...)
end
|
.around_rollback ⇒ Object
84
85
86
|
# File 'lib/active_interactor/interactor/base.rb', line 84
def around_rollback(...)
set_callback(:rollback, :around, ...)
end
|
.around_runtime_context_create ⇒ Object
88
89
90
|
# File 'lib/active_interactor/interactor/base.rb', line 88
def around_runtime_context_create(...)
set_callback(:runtime_context_create, :around, ...)
end
|
.before_fail ⇒ Object
92
93
94
|
# File 'lib/active_interactor/interactor/base.rb', line 92
def before_fail(...)
set_callback(:fail, :before, ...)
end
|
.before_input_context_create ⇒ Object
96
97
98
|
# File 'lib/active_interactor/interactor/base.rb', line 96
def before_input_context_create(...)
set_callback(:input_context_create, :before, ...)
end
|
.before_input_context_validation ⇒ Object
100
101
102
|
# File 'lib/active_interactor/interactor/base.rb', line 100
def before_input_context_validation(...)
set_callback(:input_context_validation, :before, ...)
end
|
.before_output_context_create ⇒ Object
104
105
106
|
# File 'lib/active_interactor/interactor/base.rb', line 104
def before_output_context_create(...)
set_callback(:output_context_create, :before, ...)
end
|
.before_output_context_validation ⇒ Object
108
109
110
|
# File 'lib/active_interactor/interactor/base.rb', line 108
def before_output_context_validation(...)
set_callback(:output_context_validation, :before, ...)
end
|
112
113
114
|
# File 'lib/active_interactor/interactor/base.rb', line 112
def before_perform(...)
set_callback(:perform, :before, ...)
end
|
.before_rollback ⇒ Object
116
117
118
|
# File 'lib/active_interactor/interactor/base.rb', line 116
def before_rollback(...)
set_callback(:rollback, :before, ...)
end
|
.before_runtime_context_create ⇒ Object
120
121
122
|
# File 'lib/active_interactor/interactor/base.rb', line 120
def before_runtime_context_create(...)
set_callback(:runtime_context_create, :before, ...)
end
|
.input_context_class ⇒ Object
124
125
126
|
# File 'lib/active_interactor/interactor/base.rb', line 124
def input_context_class
@input_context_class ||= const_set(:InputContext, Class.new(Context::Input))
end
|
.output_context_class ⇒ Object
128
129
130
|
# File 'lib/active_interactor/interactor/base.rb', line 128
def output_context_class
@output_context_class ||= const_set(:OutputContext, Class.new(Context::Output))
end
|
136
137
138
139
140
141
142
|
# File 'lib/active_interactor/interactor/base.rb', line 136
def perform(input_context = {}, options = {})
perform!(input_context, options)
rescue Error => e
e.result
rescue StandardError => e
Result.failure(errors: e.message)
end
|
132
133
134
|
# File 'lib/active_interactor/interactor/base.rb', line 132
def perform!(input_context = {}, options = {})
new(options).perform!(input_context)
end
|
.returns_data_matching(set_output_context_class) ⇒ Object
Also known as:
output_context, output_type
144
145
146
|
# File 'lib/active_interactor/interactor/base.rb', line 144
def returns_data_matching(set_output_context_class)
@output_context_class = set_output_context_class
end
|
.runtime_context_class ⇒ Object
150
151
152
153
154
155
156
157
|
# File 'lib/active_interactor/interactor/base.rb', line 150
def runtime_context_class
@runtime_context_class ||= begin
context_class = const_set(:RuntimeContext, Class.new(Context::Runtime))
context_class.send(:attribute_set).merge(input_context_class.send(:attribute_set).attributes)
context_class.send(:attribute_set).merge(output_context_class.send(:attribute_set).attributes)
context_class
end
end
|
.with_options(options) ⇒ Object
159
160
161
|
# File 'lib/active_interactor/interactor/base.rb', line 159
def with_options(options)
new(options)
end
|
Instance Method Details
#interact ⇒ Object
174
|
# File 'lib/active_interactor/interactor/base.rb', line 174
def interact; end
|
186
187
188
189
190
191
192
|
# File 'lib/active_interactor/interactor/base.rb', line 186
def perform(input_context = {})
perform!(input_context)
rescue Error => e
e.result
rescue StandardError => e
Result.failure(errors: e.message)
end
|
176
177
178
179
180
181
182
183
184
|
# File 'lib/active_interactor/interactor/base.rb', line 176
def perform!(input_context = {})
@raw_input = input_context.deep_dup
create_input_context
validate_input_context!
create_runtime_context
return execute_perform_with_callbacks unless @options.skip_perform_callbacks
execute_perform
end
|
#rollback ⇒ Object
194
|
# File 'lib/active_interactor/interactor/base.rb', line 194
def rollback; end
|
#with_options(options) ⇒ Object
196
197
198
199
|
# File 'lib/active_interactor/interactor/base.rb', line 196
def with_options(options)
@options = Options.new(options.deep_dup)
self
end
|