Exception: ReeMapper::ErrorWithLocation

Inherits:
Error
  • Object
show all
Defined in:
lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb

Direct Known Subclasses

CoercionError, TypeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, location = nil, field_name_parts = []) ⇒ ErrorWithLocation

Returns a new instance of ErrorWithLocation.



7
8
9
10
11
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 7

def initialize(message, location = nil, field_name_parts = [])
  @message = message
  @location = location
  @field_name_parts = field_name_parts
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 4

def location
  @location
end

Instance Method Details

#field_nameObject



20
21
22
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 20

def field_name
  @field_name_parts.reduce { "#{_1}[#{_2}]" }
end

#full_messageObject



47
48
49
50
51
52
53
54
55
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 47

def full_message(...)
  msg = super
  return msg if location.nil?

  last_sym_idx = msg.index(/\).*\n/)
  return msg if last_sym_idx.nil?

  msg.insert(last_sym_idx + 1, ", located at #{location}")
end

#messageObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 27

def message
  msg = @message

  if location
    msg = "#{msg}, located at #{location}"
  end

  return msg if @field_name_parts.empty?

  "`#{field_name}` #{msg}"
end

#prepend_field_name(part) ⇒ Object



14
15
16
17
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/errors/error_with_location.rb', line 14

def prepend_field_name(part)
  @field_name_parts.unshift part
  nil
end