Class: ActiveInteractor::Base
- Inherits:
-
Object
- Object
- ActiveInteractor::Base
- Defined in:
- lib/active_interactor/base.rb
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.
49 50 51 52 |
# File 'lib/active_interactor/base.rb', line 49 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
13 14 15 |
# File 'lib/active_interactor/base.rb', line 13 def accepts_arguments_matching(set_input_context_class) @input_context_class = set_input_context_class end |
.input_context_class ⇒ Object
9 10 11 |
# File 'lib/active_interactor/base.rb', line 9 def input_context_class @input_context_class ||= const_set(:InputContext, Class.new(Context::Input)) end |
.output_context_class ⇒ Object
18 19 20 |
# File 'lib/active_interactor/base.rb', line 18 def output_context_class @output_context_class ||= const_set(:OutputContext, Class.new(Context::Output)) end |
.perform(input_context = {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/active_interactor/base.rb', line 26 def perform(input_context = {}) perform!(input_context) rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
.perform!(input_context = {}) ⇒ Object
22 23 24 |
# File 'lib/active_interactor/base.rb', line 22 def perform!(input_context = {}) new(input_context).perform! end |
.returns_data_matching(set_output_context_class) ⇒ Object Also known as: output_context
34 35 36 |
# File 'lib/active_interactor/base.rb', line 34 def returns_data_matching(set_output_context_class) @output_context_class = set_output_context_class end |
.runtime_context_class ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/active_interactor/base.rb', line 39 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
70 |
# File 'lib/active_interactor/base.rb', line 70 def interact; end |
#perform ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/active_interactor/base.rb', line 62 def perform perform! rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
#perform! ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/active_interactor/base.rb', line 54 def perform! with_notification(:perform) do |payload| interact generate_and_validate_output_context! payload[:result] = Result.success(data: @output) end end |
#rollback ⇒ Object
71 |
# File 'lib/active_interactor/base.rb', line 71 def rollback; end |