Exception: ReeErrors::Error
- Inherits:
-
StandardError
- Object
- StandardError
- ReeErrors::Error
- Includes:
- Ree::LinkDSL
- Defined in:
- lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb
Instance Method Summary collapse
- #caller ⇒ Object
- #caller_class ⇒ Object
- #caller_module ⇒ Object
- #code ⇒ Object
- #default_msg ⇒ Object
-
#initialize(msg = nil) ⇒ Error
constructor
A new instance of Error.
- #locale ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(msg = nil) ⇒ Error
Returns a new instance of Error.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 9 def initialize(msg = nil) if !msg && !locale && !default_msg raise ArgumentError, "message, locale or default message should be specified" end = if msg msg elsif default_msg default_msg else path = (locale || code).to_s has_path = path.include?(".") if has_path pre_path = [caller_module, caller_class].compact.map { underscore(_1)}.join(".") if check_locale_exists(path) t(path, default_by_locale: :en) else t("#{pre_path}.#{path}", default_by_locale: :en) end else if caller_module mod = underscore(caller_module) klass = underscore(caller_class) if check_locale_exists(loc = "#{mod}.errors.#{klass}.#{path}") t(loc, default_by_locale: :en) else check_locale_exists(loc = "#{mod}.errors.#{path}") t(loc, default_by_locale: :en) end else end end end super() end |
Instance Method Details
#caller ⇒ Object
68 69 70 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 68 def caller self.class.instance_variable_get(:@caller) end |
#caller_class ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 88 def caller_class @caller_class ||= begin if !caller nil else c = caller if c.is_a?(Class) extract_class_name(c.to_s) else extract_class_name(c.class.to_s) end end end end |
#caller_module ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 72 def caller_module @caller_module ||= begin if !caller nil else c = caller if c.is_a?(Class) extract_module_name(c.to_s) else extract_module_name(c.class.to_s) end end end end |
#code ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 104 def code c = self.class.instance_variable_get(:@code) if !c raise ArgumentError.new( "code not specified for error => #{self.inspect}" ) end c end |
#default_msg ⇒ Object
60 61 62 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 60 def default_msg self.class.instance_variable_get(:@default_msg) end |
#locale ⇒ Object
64 65 66 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 64 def locale self.class.instance_variable_get(:@locale) end |
#type ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb', line 48 def type t = self.class.instance_variable_get(:@type) if !t raise ArgumentError.new( "type was not specified for domain error => #{self.inspect}" ) end t end |