Class: Interactors::Simple
- Inherits:
-
Object
- Object
- Interactors::Simple
- Includes:
- FunctionalInteractor
- Defined in:
- lib/interactors/simple.rb
Overview
Anonymous interactors Does two things:
- passes context to the proc
- honors #compose interface
- Only return [:error, ... ] if exception is raised
- otherwise, always return [:ok, context]
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #call(context = {}) ⇒ Object
-
#handle_error ⇒ Object
This is meant to be overridable.
-
#initialize(&blk) ⇒ Simple
constructor
A new instance of Simple.
Methods included from FunctionalInteractor
Constructor Details
#initialize(&blk) ⇒ Simple
Returns a new instance of Simple.
14 15 16 |
# File 'lib/interactors/simple.rb', line 14 def initialize(&blk) @block = blk end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
12 13 14 |
# File 'lib/interactors/simple.rb', line 12 def block @block end |
Instance Method Details
#call(context = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/interactors/simple.rb', line 18 def call(context = {}) handle_error do block.call(context) end end |
#handle_error ⇒ Object
This is meant to be overridable. Maybe you want to use something else, such as capturing network errors, or wrap around specific third-party libraries.
28 29 30 31 32 33 |
# File 'lib/interactors/simple.rb', line 28 def handle_error yield [:ok, context] rescue Exception => e [:error, e] end |