Module: Inspec::DSL::RequireOverride

Defined in:
lib/inspec/dsl_shared.rb

Instance Method Summary collapse

Instance Method Details

#__ruby_requireObject

Save the toplevel require method to load all ruby dependencies. It is used whenever the ‘require ’lib’‘ is not in libraries.



10
# File 'lib/inspec/dsl_shared.rb', line 10

alias __ruby_require require

#require(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/inspec/dsl_shared.rb', line 12

def require(path)
  rbpath = path + '.rb'
  return __ruby_require(path) if !@require_loader.exists?(rbpath)
  return false if @require_loader.loaded?(rbpath)

  # This is equivalent to calling `require 'lib'` with lib on disk.
  # We cannot rely on libraries residing on disk however.
  # TODO: Sandboxing.
  content, path, line = @require_loader.load(rbpath)
  eval(content, TOPLEVEL_BINDING, path, line) # rubocop:disable Lint/Eval
end