Class: ActiveInteractor::Base
- Inherits:
-
Object
- Object
- ActiveInteractor::Base
- Defined in:
- lib/active_interactor/base.rb
Class Method Summary collapse
- .argument(name, type, description = nil, **options) ⇒ Object
- .perform(input_context = {}) ⇒ Object
- .perform!(input_context = {}) ⇒ Object
- .returns(name, type, description = nil, **options) ⇒ 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.
33 34 35 36 |
# File 'lib/active_interactor/base.rb', line 33 def initialize(input = {}) @input = input.freeze @context = parse_input! end |
Class Method Details
.argument(name, type, description = nil, **options) ⇒ Object
6 7 8 |
# File 'lib/active_interactor/base.rb', line 6 def argument(name, type, description = nil, **) attributes[:arguments][name.to_sym] = { name: name, type: type, description: description }.merge() end |
.perform(input_context = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/active_interactor/base.rb', line 14 def perform(input_context = {}) perform!(input_context) rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
.perform!(input_context = {}) ⇒ Object
10 11 12 |
# File 'lib/active_interactor/base.rb', line 10 def perform!(input_context = {}) new(input_context).perform! end |
.returns(name, type, description = nil, **options) ⇒ Object
22 23 24 |
# File 'lib/active_interactor/base.rb', line 22 def returns(name, type, description = nil, **) attributes[:fields][name.to_sym] = { name: name, type: type, description: description }.merge() end |
Instance Method Details
#interact ⇒ Object
51 |
# File 'lib/active_interactor/base.rb', line 51 def interact; end |
#perform ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/active_interactor/base.rb', line 43 def perform perform! rescue Error => e e.result rescue StandardError => e Result.failure(errors: e.) end |
#perform! ⇒ Object
38 39 40 41 |
# File 'lib/active_interactor/base.rb', line 38 def perform! interact Result.success(data: parse_output!) end |
#rollback ⇒ Object
52 |
# File 'lib/active_interactor/base.rb', line 52 def rollback; end |