Exception: CodeError::Base
- Inherits:
-
StandardError
- Object
- StandardError
- CodeError::Base
- Defined in:
- lib/code_error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #data(masked = nil) ⇒ Object
-
#initialize(code = nil, msg = nil, info = {}) ⇒ Base
constructor
A new instance of Base.
- #internal? ⇒ Boolean
- #message ⇒ Object
- #msg(masked = nil) ⇒ Object
Constructor Details
#initialize(code = nil, msg = nil, info = {}) ⇒ Base
Returns a new instance of Base.
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 |
# File 'lib/code_error.rb', line 16 def initialize(code = nil, msg = nil, info = {}) @code = code @info = info if error_codes.keys.include?(code) @status = error_codes[code][:status] @msg = error_codes[code][:msg] @masked = error_codes[code][:masked] || false if msg == :masked @masked = true elsif msg.is_a?(String) @masked = false @msg = msg end elsif code == config[:success][:code] @code = config[:success][:code] @status = config[:success][:status] @msg = config[:success][:msg] else # unknown code @status = config[:internal][:status] if code.is_a?(String) @code = config[:internal][:code] @msg = code else @code = code || config[:internal][:code] @msg = msg || config[:internal][:msg] end end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
14 15 16 |
# File 'lib/code_error.rb', line 14 def code @code end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
14 15 16 |
# File 'lib/code_error.rb', line 14 def info @info end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/code_error.rb', line 14 def status @status end |
Instance Method Details
#data(masked = nil) ⇒ Object
50 51 52 53 |
# File 'lib/code_error.rb', line 50 def data(masked = nil) msg = (@code, @msg, masked) { status: @status, code: @code, msg: msg, info: @info } end |
#internal? ⇒ Boolean
59 60 61 |
# File 'lib/code_error.rb', line 59 def internal? @status == config[:internal][:status] end |
#message ⇒ Object
46 47 48 |
# File 'lib/code_error.rb', line 46 def self.data.inspect end |
#msg(masked = nil) ⇒ Object
55 56 57 |
# File 'lib/code_error.rb', line 55 def msg(masked = nil) (@code, @msg, masked) end |