Module: LunaPark::Extensions::HasErrors::InstanceMethods

Defined in:
lib/luna_park/extensions/has_errors.rb

Instance Method Summary collapse

Instance Method Details

#error(title, msg = nil, **attrs) ⇒ Object

Raise error defined in class

Examples:

class Service
  include LunaPark::Extensions::HasErrors

  class LogicError < LunaPark::Errors::Business; end
end

Service.new.error :logic_error # => raise LogicError

Parameters:

  • title (Symbol|String)
    • Title of error

  • msg (String) (defaults to: nil)
    • Message of error

  • **attrs
    • See @LunaPark::Errors::Base#new



54
55
56
57
# File 'lib/luna_park/extensions/has_errors.rb', line 54

def error(title, msg = nil, **attrs)
  class_name = self.class.error_class_name(title)
  raise self.class.const_get(class_name).new msg, **attrs
end