Module: Kernel

Defined in:
lib/dead_end/core_ext.rb

Overview

Monkey patch kernel to ensure that all ‘require` calls call the same method

Class Method Summary collapse

Class Method Details

.dead_end_original_loadObject



62
# File 'lib/dead_end/core_ext.rb', line 62

alias_method :dead_end_original_load, :load

.dead_end_original_requireObject



60
# File 'lib/dead_end/core_ext.rb', line 60

alias_method :dead_end_original_require, :require

.dead_end_original_require_relativeObject



61
# File 'lib/dead_end/core_ext.rb', line 61

alias_method :dead_end_original_require_relative, :require_relative

.load(file, wrap = false) ⇒ Object



64
65
66
67
68
# File 'lib/dead_end/core_ext.rb', line 64

def load(file, wrap = false)
  dead_end_original_load(file)
rescue SyntaxError => e
  DeadEnd.handle_error(e)
end

.require(file) ⇒ Object



70
71
72
73
74
# File 'lib/dead_end/core_ext.rb', line 70

def require(file)
  dead_end_original_require(file)
rescue SyntaxError => e
  DeadEnd.handle_error(e)
end

.require_relative(file) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dead_end/core_ext.rb', line 76

def require_relative(file)
  if Pathname.new(file).absolute?
    dead_end_original_require file
  else
    relative_from = caller_locations(1..1).first
    relative_from_path = relative_from.absolute_path || relative_from.path
    dead_end_original_require File.expand_path("../#{file}", relative_from_path)
  end
rescue SyntaxError => e
  DeadEnd.handle_error(e)
end