Module: Mu::Action
- Defined in:
- lib/mu/action.rb,
lib/mu/action/version.rb
Overview
Provides an interactor pattern implementation with hooks, metadata tracking, and result wrapping.
Defined Under Namespace
Modules: ClassMethods, HookPropagator, Initializer, MetaPropAdder Classes: Failure, FailureError, Result, Success
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
Instance Method Summary collapse
- #Failure(error, **meta) ⇒ Object
-
#run ⇒ Object
rubocop:enable Naming/MethodName.
- #run! ⇒ Object
-
#Success(value) ⇒ Object
rubocop:disable Naming/MethodName.
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mu/action.rb', line 10 def self.included(base) base.class_eval do extend Literal::Properties extend ClassMethods include Initializer singleton_class.prepend(MetaPropAdder) singleton_class.prepend(HookPropagator) attr_reader :meta end end |
Instance Method Details
#Failure(error, **meta) ⇒ Object
181 182 |
# File 'lib/mu/action.rb', line 181 def Failure(error, **) = raise FailureError.new(error, meta:) # rubocop:enable Naming/MethodName |
#run ⇒ Object
rubocop:enable Naming/MethodName
184 185 186 187 188 |
# File 'lib/mu/action.rb', line 184 def run run! rescue FailureError => e Failure.new(e.error, meta: { failure_error: e, **, **e. }) end |
#run! ⇒ Object
190 191 192 |
# File 'lib/mu/action.rb', line 190 def run! with_hooks { call } end |
#Success(value) ⇒ Object
rubocop:disable Naming/MethodName
180 |
# File 'lib/mu/action.rb', line 180 def Success(value) = self.class.const_get(:Success).new(value, meta:) |