Exception: Cupper::Errors::CupperError
- Inherits:
-
StandardError
- Object
- StandardError
- Cupper::Errors::CupperError
- Defined in:
- lib/cupper/errors.rb
Direct Known Subclasses
CupperfileLoadError, CupperfileSyntaxError, EnvironmentNonExistentCWD, LocalDataDirectoryNotAccessible, NoEnvironmentError
Instance Attribute Summary collapse
-
#extra_data ⇒ Object
Returns the value of attribute extra_data.
Class Method Summary collapse
- .error_key(key = nil, namespace = nil) ⇒ Object
- .error_message(message) ⇒ Object
- .error_namespace(namespace) ⇒ Object
Instance Method Summary collapse
-
#error_key ⇒ Object
The key for the error message.
-
#error_message ⇒ Object
The error message for this error.
-
#error_namespace ⇒ Object
The default error namespace which is used for the error key.
-
#initialize(*args) ⇒ CupperError
constructor
A new instance of CupperError.
-
#status_code ⇒ Integer
This is the exit code that should be used when exiting from this exception.
- #translate_error(opts) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CupperError
Returns a new instance of CupperError.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cupper/errors.rb', line 28 def initialize(*args) key = args.shift if args.first.is_a?(Symbol) = args.shift if args.first.is_a?(Hash) ||= {} @extra_data = .dup [:_key] ||= error_key [:_namespace] ||= error_namespace [:_key] = key if key I18n.load_path << File.("../../../templates/locales/en.yml", __FILE__) if [:_key] = translate_error() else = end super() end |
Instance Attribute Details
#extra_data ⇒ Object
Returns the value of attribute extra_data.
8 9 10 |
# File 'lib/cupper/errors.rb', line 8 def extra_data @extra_data end |
Class Method Details
.error_key(key = nil, namespace = nil) ⇒ Object
10 11 12 13 |
# File 'lib/cupper/errors.rb', line 10 def self.error_key(key=nil, namespace=nil) define_method(:error_key) { key } error_namespace(namespace) if namespace end |
.error_message(message) ⇒ Object
15 16 17 |
# File 'lib/cupper/errors.rb', line 15 def self.() define_method(:error_message) { } end |
.error_namespace(namespace) ⇒ Object
19 20 21 |
# File 'lib/cupper/errors.rb', line 19 def self.error_namespace(namespace) define_method(:error_namespace) { namespace } end |
Instance Method Details
#error_key ⇒ Object
The key for the error message. This should be set using the error_key method but can be overridden here if needed.
58 |
# File 'lib/cupper/errors.rb', line 58 def error_key; nil; end |
#error_message ⇒ Object
The error message for this error. This is used if no error_key is specified for a translatable error message.
49 |
# File 'lib/cupper/errors.rb', line 49 def ; "No error message"; end |
#error_namespace ⇒ Object
The default error namespace which is used for the error key. This can be overridden here or by calling the “error_namespace” class method.
54 |
# File 'lib/cupper/errors.rb', line 54 def error_namespace; "cupper.errors"; end |
#status_code ⇒ Integer
This is the exit code that should be used when exiting from this exception.
64 |
# File 'lib/cupper/errors.rb', line 64 def status_code; 1; end |
#translate_error(opts) ⇒ Object
23 24 25 26 |
# File 'lib/cupper/errors.rb', line 23 def translate_error(opts) return nil if !opts[:_key] I18n.t("#{opts[:_namespace]}.#{opts[:_key]}", opts) end |