Module: Mu::Action::ClassMethods
- Defined in:
- lib/mu/action.rb
Overview
Class methods added to action classes when including Mu::Action. Provides hook registration, execution methods, and result type definition.
Instance Method Summary collapse
- #after(*method_names, &block) ⇒ Object
- #after_hooks ⇒ Object
- #around(*method_names, &block) ⇒ Object
- #around_hooks ⇒ Object
- #before(*method_names, &block) ⇒ Object
- #before_hooks ⇒ Object
- #call ⇒ Object
- #call! ⇒ Object
- #result(type) ⇒ Object
Instance Method Details
#after(*method_names, &block) ⇒ Object
116 |
# File 'lib/mu/action.rb', line 116 def after(*method_names, &block) = register_hook(after_hooks, method_names, block, name: :after) |
#after_hooks ⇒ Object
120 |
# File 'lib/mu/action.rb', line 120 def after_hooks = (@after_hooks ||= []) |
#around(*method_names, &block) ⇒ Object
114 |
# File 'lib/mu/action.rb', line 114 def around(*method_names, &block) = register_hook(around_hooks, method_names, block, name: :around) |
#around_hooks ⇒ Object
118 |
# File 'lib/mu/action.rb', line 118 def around_hooks = (@around_hooks ||= []) |
#before(*method_names, &block) ⇒ Object
115 |
# File 'lib/mu/action.rb', line 115 def before(*method_names, &block) = register_hook(before_hooks, method_names, block, name: :before) |
#before_hooks ⇒ Object
119 |
# File 'lib/mu/action.rb', line 119 def before_hooks = (@before_hooks ||= []) |
#call ⇒ Object
122 |
# File 'lib/mu/action.rb', line 122 def call(...) = new(...).run |
#call! ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mu/action.rb', line 124 def call!(...) result = new(...).run! case result in Success(value:) value in Failure(meta: { failure_error: }) raise failure_error else result end end |
#result(type) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/mu/action.rb', line 136 def result(type) success_class = Class.new(::Mu::Action::Success) do prop :value, type, :positional, default: nil end const_set(:Success, success_class) end |