Exception: MelissaData::Errors::MelissaDataError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/melissadata/errors.rb

Overview

Main superclass of any errors in MelissaData. This provides some convenience methods for setting the error key. The error key is used as a default message from I18n.

Direct Known Subclasses

DiscNotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, *args) ⇒ MelissaDataError

Returns a new instance of MelissaDataError.



53
54
55
56
57
58
59
# File 'lib/melissadata/errors.rb', line 53

def initialize(message=nil, *args)
  message = { :_key => message } if message && !message.is_a?(Hash)
  message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
  message = translate_error(message)

  super
end

Class Method Details

.error_key(key = nil, namespace = nil) ⇒ Object



44
45
46
47
# File 'lib/melissadata/errors.rb', line 44

def self.error_key(key=nil, namespace=nil)
  define_method(:error_key) { key }
  error_namespace(namespace) if namespace
end

.error_namespace(namespace) ⇒ Object



49
50
51
# File 'lib/melissadata/errors.rb', line 49

def self.error_namespace(namespace)
  define_method(:error_namespace) { namespace }
end

Instance Method Details

#error_keyObject

The key for the error message. This should be set using the error_key method but can be overridden here if needed.



68
# File 'lib/melissadata/errors.rb', line 68

def error_key; nil; end

#error_namespaceObject

The default error namespace which is used for the error key. This can be overridden here or by calling the “error_namespace” class method.



64
# File 'lib/melissadata/errors.rb', line 64

def error_namespace; "melissadata.errors"; end