Class: ActiveOperation::Base
- Inherits:
-
Object
- Object
- ActiveOperation::Base
- Includes:
- ActiveSupport::Callbacks, SmartProperties
- Defined in:
- lib/active_operation/base.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #completed? ⇒ Boolean
- #halted? ⇒ Boolean
-
#initialize(*positional_arguments, **keyword_arguments) ⇒ Base
constructor
A new instance of Base.
- #succeeded? ⇒ Boolean
Constructor Details
#initialize(*positional_arguments, **keyword_arguments) ⇒ Base
Returns a new instance of Base.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/active_operation/base.rb', line 85 def initialize(*positional_arguments, **keyword_arguments) expected_positional_arguments = self.class.inputs.select(&:positional?) raise ArgumentError, "wrong number of arguments" if positional_arguments.length != expected_positional_arguments.length super( keyword_arguments.merge( expected_positional_arguments.zip(positional_arguments).map { |input, value| [input.name, value] }.to_h ) ) end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
6 7 8 |
# File 'lib/active_operation/base.rb', line 6 def error @error end |
#output ⇒ Object
Returns the value of attribute output.
5 6 7 |
# File 'lib/active_operation/base.rb', line 5 def output @output end |
Class Method Details
.call(*args) ⇒ Object
17 18 19 |
# File 'lib/active_operation/base.rb', line 17 def call(*args) new(*args).call end |
.inputs ⇒ Object
21 22 23 |
# File 'lib/active_operation/base.rb', line 21 def inputs [] end |
Instance Method Details
#call ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/active_operation/base.rb', line 97 def call run_callbacks :execute do catch(:abort) do next if completed? @output = execute self.state = :succeeded end end run_callbacks :halted if halted? run_callbacks :succeeded if succeeded? self.output rescue => error self.state = :failed self.error = error run_callbacks :error raise end |
#completed? ⇒ Boolean
130 131 132 |
# File 'lib/active_operation/base.rb', line 130 def completed? halted? || succeeded? end |
#halted? ⇒ Boolean
122 123 124 |
# File 'lib/active_operation/base.rb', line 122 def halted? state == :halted end |
#succeeded? ⇒ Boolean
126 127 128 |
# File 'lib/active_operation/base.rb', line 126 def succeeded? state == :succeeded end |