module LiveAST::Loader

Public Class Methods

find_file(file) click to toggle source
# File lib/live_ast/loader.rb, line 42
def find_file(file)
  if file.index Linker::REVISION_TOKEN
    raise "refusing to load file with revision token: `#{file}'"
  end

  search_paths(file) or
    raise LoadError, "cannot load such file -- #{file}"
end
load(file, wrap) click to toggle source
# File lib/live_ast/loader.rb, line 6
def load(file, wrap)
  file = find_file(file)

  # guards to protect toplevel locals
  header, footer, warnings_ok = header_footer(wrap)

  parser_src = Reader.read(file)
  evaler_src = +"" << header << parser_src << footer

  run = lambda do
    Evaler.eval(parser_src, evaler_src, TOPLEVEL_BINDING, file, 1)
  end
  warnings_ok ? run.call : suppress_warnings(&run)
  true
end
search_paths(file) click to toggle source
# File lib/live_ast/loader.rb, line 51
def search_paths(file)
  return file if File.file? file

  $LOAD_PATH.each do |path|
    target = File.join(path, file)
    return target if File.file? target
  end
  nil
end
suppress_warnings() { || ... } click to toggle source
# File lib/live_ast/loader.rb, line 32
def suppress_warnings
  previous = $VERBOSE
  $VERBOSE = nil
  begin
    yield
  ensure
    $VERBOSE ||= previous
  end
end