lib/irb/ext/loader.rb


DEFINITIONS

This source file includes following functions.


   1  module IRB
   2    class LoadAbort < Exception;end
   3  
   4    module IrbLoader
   5      @RCS_ID='-$Id: loader.rb,v 1.1 2002/07/09 11:17:17 keiju Exp $-'
   6      alias ruby_load load
   7      alias ruby_require require
   8  
   9      def irb_load(fn, priv = nil)
  10        path = search_file_from_ruby_path(fn)
  11        raise LoadError, "No such file to load -- #{fn}" unless path
  12  
  13        load_file(path, priv)
  14      end
  15  
  16      def search_file_from_ruby_path(fn)
  17        if /^#{Regexp.quote(File::Separator)}/ =~ fn
  18          return fn if File.exist?(fn)
  19          return nil
  20        end
  21  
  22        for path in $:
  23          if File.exist?(f = File.join(path, fn))
  24            return f
  25          end
  26        end
  27        return nil
  28      end
  29  
  30      def source_file(path)
  31        irb.suspend_name(path, File.basename(path)) do
  32          irb.suspend_input_method(FileInputMethod.new(path)) do
  33            |back_io|
  34            irb.signal_status(:IN_LOAD) do 
  35              if back_io.kind_of?(FileInputMethod)
  36                irb.eval_input
  37              else
  38                begin
  39                  irb.eval_input
  40                rescue LoadAbort
  41                  print "load abort!!\n"
  42                end
  43              end
  44            end
  45          end
  46        end
  47      end
  48  
  49      def load_file(path, priv = nil)
  50        irb.suspend_name(path, File.basename(path)) do
  51          
  52          if priv
  53            ws = WorkSpace.new(Module.new)
  54          else
  55            ws = WorkSpace.new
  56          end
  57          irb.suspend_workspace(ws) do
  58            irb.suspend_input_method(FileInputMethod.new(path)) do
  59              |back_io|
  60              irb.signal_status(:IN_LOAD) do 
  61  #             p irb.conf
  62                if back_io.kind_of?(FileInputMethod)
  63                  irb.eval_input
  64                else
  65                  begin
  66                    irb.eval_input
  67                  rescue LoadAbort
  68                    print "load abort!!\n"
  69                  end
  70                end
  71              end
  72            end
  73          end
  74        end
  75      end
  76  
  77      def old
  78        back_io = @io
  79        back_path = @irb_path
  80        back_name = @irb_name
  81        back_scanner = @irb.scanner
  82        begin
  83          @io = FileInputMethod.new(path)
  84          @irb_name = File.basename(path)
  85          @irb_path = path
  86          @irb.signal_status(:IN_LOAD) do
  87            if back_io.kind_of?(FileInputMethod)
  88              @irb.eval_input
  89            else
  90              begin
  91                @irb.eval_input
  92              rescue LoadAbort
  93                print "load abort!!\n"
  94              end
  95            end
  96          end
  97        ensure
  98          @io = back_io
  99          @irb_name = back_name
 100          @irb_path = back_path
 101          @irb.scanner = back_scanner
 102        end
 103      end
 104    end
 105  end
 106