source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/irb/ext/loader.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.3 KB
Line 
1#
2# loader.rb -
3# $Release Version: 0.9.5$
4# $Revision: 11708 $
5# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
6# by Keiju ISHITSUKA([email protected])
7#
8# --
9#
10#
11#
12
13
14module IRB
15 class LoadAbort < Exception;end
16
17 module IrbLoader
18 @RCS_ID='-$Id: loader.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
19
20 alias ruby_load load
21 alias ruby_require require
22
23 def irb_load(fn, priv = nil)
24 path = search_file_from_ruby_path(fn)
25 raise LoadError, "No such file to load -- #{fn}" unless path
26
27 load_file(path, priv)
28 end
29
30 def search_file_from_ruby_path(fn)
31 if /^#{Regexp.quote(File::Separator)}/ =~ fn
32 return fn if File.exist?(fn)
33 return nil
34 end
35
36 for path in $:
37 if File.exist?(f = File.join(path, fn))
38 return f
39 end
40 end
41 return nil
42 end
43
44 def source_file(path)
45 irb.suspend_name(path, File.basename(path)) do
46 irb.suspend_input_method(FileInputMethod.new(path)) do
47 |back_io|
48 irb.signal_status(:IN_LOAD) do
49 if back_io.kind_of?(FileInputMethod)
50 irb.eval_input
51 else
52 begin
53 irb.eval_input
54 rescue LoadAbort
55 print "load abort!!\n"
56 end
57 end
58 end
59 end
60 end
61 end
62
63 def load_file(path, priv = nil)
64 irb.suspend_name(path, File.basename(path)) do
65
66 if priv
67 ws = WorkSpace.new(Module.new)
68 else
69 ws = WorkSpace.new
70 end
71 irb.suspend_workspace(ws) do
72 irb.suspend_input_method(FileInputMethod.new(path)) do
73 |back_io|
74 irb.signal_status(:IN_LOAD) do
75# p irb.conf
76 if back_io.kind_of?(FileInputMethod)
77 irb.eval_input
78 else
79 begin
80 irb.eval_input
81 rescue LoadAbort
82 print "load abort!!\n"
83 end
84 end
85 end
86 end
87 end
88 end
89 end
90
91 def old
92 back_io = @io
93 back_path = @irb_path
94 back_name = @irb_name
95 back_scanner = @irb.scanner
96 begin
97 @io = FileInputMethod.new(path)
98 @irb_name = File.basename(path)
99 @irb_path = path
100 @irb.signal_status(:IN_LOAD) do
101 if back_io.kind_of?(FileInputMethod)
102 @irb.eval_input
103 else
104 begin
105 @irb.eval_input
106 rescue LoadAbort
107 print "load abort!!\n"
108 end
109 end
110 end
111 ensure
112 @io = back_io
113 @irb_name = back_name
114 @irb_path = back_path
115 @irb.scanner = back_scanner
116 end
117 end
118 end
119end
120
Note: See TracBrowser for help on using the repository browser.