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

Instance Method Details

#after(&block) ⇒ Object



116
# File 'lib/mu/action.rb', line 116

def after(&block) = after_hooks << block

#after_hooksObject



120
# File 'lib/mu/action.rb', line 120

def after_hooks = (@after_hooks ||= [])

#around(&block) ⇒ Object



114
# File 'lib/mu/action.rb', line 114

def around(&block) = around_hooks << block

#around_hooksObject



118
# File 'lib/mu/action.rb', line 118

def around_hooks = (@around_hooks ||= [])

#before(&block) ⇒ Object



115
# File 'lib/mu/action.rb', line 115

def before(&block) = before_hooks << block

#before_hooksObject



119
# File 'lib/mu/action.rb', line 119

def before_hooks = (@before_hooks ||= [])

#callObject



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