module LunaPark::Extensions::HasErrors::ClassMethods
Public Instance Methods
business_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
click to toggle source
Define business error
@example
class Service include LunaPark::Extensions::HasErrors business_error :logic_error, { (1 + 1).to_s } end logic_error = Service::LogicError.new logic_error.is_a? LunaPark::Errors::Business # => true logic_error.message # => '2'
# File lib/luna_park/extensions/has_errors.rb, line 74 def business_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block) error_class = Class.new(Errors::Business) error_class.message(txt, i18n_key: i18n_key, &default_message_block) error_class.notify(notify) const_set(error_class_name(title), error_class) end
Also aliased as: error
error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
Alias for business error
Alias for: business_error
error_class_name(title)
click to toggle source
Get error class name
@example when title is string
error_class_name('CamelCase') # => 'CamelCase'
@example when title is symbol
error_class_name(:snake_case) # => 'SnakeCase'
@param [String|Symbol] title - short alias for error
# File lib/luna_park/extensions/has_errors.rb, line 115 def error_class_name(title) case title when String then title when Symbol then title.to_s.split('_').collect!(&:capitalize).join else raise ArgumentError, "Unknown type `#{title}` for error title" end end
system_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
click to toggle source
Define business error
@example
class Service include LunaPark::Extensions::HasErrors system_error :tech_error, 'Custom message' end tech_error = Service::TechError.new tech_error.is_a? LunaPark::Errors::System # => true tech_error.message # => 'Custom message'
# File lib/luna_park/extensions/has_errors.rb, line 98 def system_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block) error_class = Class.new(Errors::System) error_class.message(txt, i18n_key: i18n_key, &default_message_block) error_class.notify(notify) const_set(error_class_name(title), error_class) end