Exception: Uinit::Type::Error

Inherits:
TypeError
  • Object
show all
Defined in:
lib/uinit/type/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_message, types, depth, trace = []) ⇒ Error

Returns a new instance of Error.



6
7
8
9
10
11
12
13
# File 'lib/uinit/type/error.rb', line 6

def initialize(error_message, types, depth, trace = [])
  super()

  @error_message = error_message
  @types = types
  @depth = depth
  @traces = trace
end

Instance Attribute Details

#depthObject (readonly)

Returns the value of attribute depth.



15
16
17
# File 'lib/uinit/type/error.rb', line 15

def depth
  @depth
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



15
16
17
# File 'lib/uinit/type/error.rb', line 15

def error_message
  @error_message
end

#instanceObject (readonly)

Returns the value of attribute instance.



15
16
17
# File 'lib/uinit/type/error.rb', line 15

def instance
  @instance
end

#tracesObject (readonly)

Returns the value of attribute traces.



15
16
17
# File 'lib/uinit/type/error.rb', line 15

def traces
  @traces
end

#typesObject (readonly)

Returns the value of attribute types.



15
16
17
# File 'lib/uinit/type/error.rb', line 15

def types
  @types
end

#valueObject

Returns the value of attribute value.



16
17
18
# File 'lib/uinit/type/error.rb', line 16

def value
  @value
end

Instance Method Details

#messageObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/uinit/type/error.rb', line 23

def message
  msg = error_message

  msg =
    if types.size == 1
      "#{msg}\nType: #{types.first}"
    else
      "#{msg}\nTypes:\n  #{types * "\n  "}"
    end

  msg = "#{msg}\nTraces: #{traces.join}" unless traces.empty?

  msg = "#{msg}\nValue: #{value.inspect}" if value

  msg
end

#trace(type, trace) ⇒ Object



18
19
20
21
# File 'lib/uinit/type/error.rb', line 18

def trace(type, trace)
  types.unshift(type)
  traces.unshift(trace)
end