Exception: Literal::TypeError

Inherits:
TypeError
  • Object
show all
Includes:
Error
Defined in:
lib/literal/errors/type_error.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

INDENT =
"  "

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ TypeError

Returns a new instance of TypeError.



59
60
61
62
63
# File 'lib/literal/errors/type_error.rb', line 59

def initialize(context:)
	@context = context

	super()
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



89
90
91
# File 'lib/literal/errors/type_error.rb', line 89

def deconstruct_keys(keys)
	to_h.slice(*keys)
end

#messageObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/literal/errors/type_error.rb', line 65

def message
	message = +"Type mismatch\n\n"

	@context.descend do |c, level|
		idt = INDENT * level
		if c.receiver || c.method
			message << idt
			message << c.receiver.class.inspect if c.receiver
			message << c.method if c.method
			message << " (from #{backtrace[1]})" if level.zero?
			message << "\n"
		end
		if c.label
			idt << INDENT
			message << idt << c.label << "\n"
		end
		if c.expected && c.children.empty?
			message << idt << "  Expected: #{c.expected.inspect}\n"
			message << idt << "  Actual (#{c.actual.class}): #{c.actual.inspect}\n"
		end
	end
	message
end

#to_hObject



93
94
95
# File 'lib/literal/errors/type_error.rb', line 93

def to_h
	@context.to_h
end