Method: Actionizer::ClassMethods#method_missing

Defined in:
lib/actionizer.rb

#method_missing(method_name, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/actionizer.rb', line 16

def method_missing(method_name, *args, &block)
  instance = new(*args)

  if method_name.to_s.end_with?('!')
    method_name = method_name.to_s.chomp('!').to_sym
    instance.raise_on_failure = true
  end

  if instance.respond_to?(method_name)
    error = defined_inputs.check_for_param_error(method_name, *args)
    if error
      raise Actionizer::Failure.new('Failed.', Actionizer::Result.new(error: error).tap(&:fail))
    end

    instance.tap(&method_name).output
  else
    super
  end
rescue Actionizer::Failure => af
  if instance.raise_on_failure
    raise af
  end

  af.output
end