Class: ActiveInteractor::Base
- Inherits:
-
Object
- Object
- ActiveInteractor::Base
- Includes:
- Type::HasTypes
- Defined in:
- lib/active_interactor/base.rb
Constant Summary
Constants included from Type::HasTypes
Class Method Summary collapse
- .accepts_arguments_matching(set_input_context_class) ⇒ Object (also: input_context)
- .input_context_class ⇒ Object
- .output_context_class ⇒ Object
- .perform(input_context = {}) ⇒ Object
- .perform!(input_context = {}) ⇒ Object
- .returns_data_matching(set_output_context_class) ⇒ Object (also: output_context)
- .runtime_context_class ⇒ Object
Instance Method Summary collapse
-
#initialize(input = {}) ⇒ Base
constructor
A new instance of Base.
- #interact ⇒ Object
- #perform ⇒ Object
- #perform! ⇒ Object
- #rollback ⇒ Object
Constructor Details
#initialize(input = {}) ⇒ Base
Returns a new instance of Base.
51 52 53 54 |
# File 'lib/active_interactor/base.rb', line 51 def initialize(input = {}) @raw_input = input.dup validate_input_and_generate_runtime_context! end |
Class Method Details
.accepts_arguments_matching(set_input_context_class) ⇒ Object Also known as: input_context
15 16 17 |
# File 'lib/active_interactor/base.rb', line 15 def accepts_arguments_matching(set_input_context_class) @input_context_class = set_input_context_class end |
.input_context_class ⇒ Object
11 12 13 |
# File 'lib/active_interactor/base.rb', line 11 def input_context_class @input_context_class ||= const_set(:InputContext, Class.new(Context::Input)) end |
.output_context_class ⇒ Object
20 21 22 |
# File 'lib/active_interactor/base.rb', line 20 def output_context_class @output_context_class ||= const_set(:OutputContext, Class.new(Context::Output)) end |
.perform(input_context = {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/active_interactor/base.rb', line 28 def perform(input_context = {}) perform!(input_context) rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
.perform!(input_context = {}) ⇒ Object
24 25 26 |
# File 'lib/active_interactor/base.rb', line 24 def perform!(input_context = {}) new(input_context).perform! end |
.returns_data_matching(set_output_context_class) ⇒ Object Also known as: output_context
36 37 38 |
# File 'lib/active_interactor/base.rb', line 36 def returns_data_matching(set_output_context_class) @output_context_class = set_output_context_class end |
.runtime_context_class ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/active_interactor/base.rb', line 41 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 |
Instance Method Details
#interact ⇒ Object
72 |
# File 'lib/active_interactor/base.rb', line 72 def interact; end |
#perform ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/active_interactor/base.rb', line 64 def perform perform! rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
#perform! ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/active_interactor/base.rb', line 56 def perform! with_notification(:perform) do |payload| interact generate_and_validate_output_context! payload[:result] = Result.success(data: @output) end end |
#rollback ⇒ Object
73 |
# File 'lib/active_interactor/base.rb', line 73 def rollback; end |