Class: Andromeda::InfoMsg

Inherits:
Object show all
Defined in:
lib/andromeda/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = '', details = {}) ⇒ InfoMsg

Returns a new instance of InfoMsg.



14
15
16
17
18
19
# File 'lib/andromeda/error.rb', line 14

def initialize(msg = '', details = {})
  @msg     = msg
  @details = details
  @cause   = details[:cause]
  details.delete :cause if @cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



11
12
13
# File 'lib/andromeda/error.rb', line 11

def cause
  @cause
end

#detailsObject (readonly)

Returns the value of attribute details.



10
11
12
# File 'lib/andromeda/error.rb', line 10

def details
  @details
end

#msgObject (readonly)

Returns the value of attribute msg.



12
13
14
# File 'lib/andromeda/error.rb', line 12

def msg
  @msg
end

Class Method Details

.str(msg = '', details = {}, cause_ = nil) ⇒ Object



5
6
7
8
# File 'lib/andromeda/error.rb', line 5

def self.str(msg = '', details = {}, cause_ = nil)
  details[:cause] = cause_ if cause_
  (InfoMsg.new msg, details).to_s
end

Instance Method Details

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/andromeda/error.rb', line 21

def to_s
  out = msg.dup
  if details && details.length > 0
    if cause
      out << " (cause = #{cause}; details = \{"
    else
      out << ' (details = {'
    end
    details.each_pair { |k,v| out << " #{k}: #{v}" }
    out << ' })'
  else
    out << " (cause = #{cause})" if cause
  end
  out << '.'
  out
end