class Nucleon::Errors::NucleonError

Attributes

extra_data[RW]

Public Class Methods

error_key(key = nil, namespace = nil) click to toggle source
# File lib/core/errors.rb, line 40
def self.error_key(key = nil, namespace = nil)
  define_method(:error_key) { key }
  error_namespace(namespace) if namespace
end
error_message(message) click to toggle source
# File lib/core/errors.rb, line 48
def self.error_message(message)
  define_method(:error_message) { message }
end
error_namespace(namespace) click to toggle source
# File lib/core/errors.rb, line 55
def self.error_namespace(namespace)
  define_method(:error_namespace) { namespace }
end
new(*args) click to toggle source
# File lib/core/errors.rb, line 13
def initialize(*args)
  key     = args.shift if args.first.is_a?(Symbol)
  message = args.shift if args.first.is_a?(Hash)
  message ||= {}
  
  @extra_data = message.dup
  
  message[:key]       ||= error_key
  message[:namespace] ||= error_namespace
  message[:key]       = key if key

  if message[:key]
    message = translate_error(message)
  else
    message = error_message
  end

  super(message)
end
status_code(code) click to toggle source
# File lib/core/errors.rb, line 62
def self.status_code(code)
  define_method(:status_code) { code }
end

Public Instance Methods

error_key() click to toggle source
# File lib/core/errors.rb, line 44
def error_key; nil; end
error_message() click to toggle source
# File lib/core/errors.rb, line 51
def error_message; "No error message"; end
error_namespace() click to toggle source
# File lib/core/errors.rb, line 58
def error_namespace; "nucleon.errors"; end
status_code() click to toggle source
# File lib/core/errors.rb, line 65
def status_code; 1; end

Protected Instance Methods

translate_error(options) click to toggle source
# File lib/core/errors.rb, line 70
def translate_error(options)
  return nil unless options[:key]
  I18n.t("#{options[:namespace]}.#{options[:key]}", options)
end