Module: IRT::Session
Constant Summary collapse
- @@exit_all =
false
Instance Method Summary collapse
- #enter(mode, obj = nil) ⇒ Object
- #eval_input(new_context, mode) ⇒ Object
- #exit ⇒ Object
- #exit_all=(bool) ⇒ Object
- #exit_all? ⇒ Boolean
- #run_file(file_path = IRT.irt_file) ⇒ Object
Instance Method Details
#enter(mode, obj = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/irt/session.rb', line 13 def enter(mode, obj=nil) IRT.log.print if IRT.tail_on_irt ws = obj ? IRB::WorkSpace.new(obj) : IRB.CurrentContext.workspace new_irb = IRB::Irb.new(ws) IRT.session_no += 1 main_name = mode == :inspect ? IRB.CurrentContext.current_line.match(/^\s*(?:irb|irt|irt_inspect)\s+(.*)$/).captures[0].strip : new_irb.context.workspace.main.to_s main_name = main_name[0..30] + '...' if main_name.size > 30 new_irb.context.irb_name = "irt##{IRT.session_no}(#{main_name})" new_irb.context.irb_path = "(irt##{IRT.session_no})" set_binding_file_pointers(new_irb.context) if mode == :binding eval_input(new_irb.context, mode) end |
#eval_input(new_context, mode) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/irt/session.rb', line 28 def eval_input(new_context, mode) new_context.parent_context = IRB.CurrentContext new_context.set_last_value( IRB.CurrentContext.last_value ) unless (mode == :inspect || mode == :binding) new_context.irt_mode = mode new_context.backtrace_map = IRB.CurrentContext.backtrace_map if mode == :interactive IRB.conf[:MAIN_CONTEXT] = new_context IRT.log.add_hunk IRT.log.status << [new_context.irb_name, mode] IRT.log.print_status unless mode == :file old_trap = trap('SIGINT'){new_context.irb.signal_handle} catch(:IRB_EXIT) { new_context.irb.eval_input } begin throw(:IRB_EXIT) ; rescue Exception ; end if @@exit_all ensure IRT::Session.exit unless @@exit_all trap 'SIGINT', old_trap if old_trap end |
#exit ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/irt/session.rb', line 45 def exit exiting_context = IRB.conf[:MAIN_CONTEXT] resuming_context = exiting_context.parent_context return unless resuming_context exiting_mode = exiting_context.irt_mode resuming_context.set_last_value( exiting_context.last_value ) \ unless (exiting_mode == :inspect || exiting_mode == :binding) IRB.conf[:MAIN_CONTEXT] = resuming_context IRT.log.pop_status IRT.log.print_status unless resuming_context.irt_mode == :file IRT.log.add_hunk end |
#exit_all=(bool) ⇒ Object
9 10 11 |
# File 'lib/irt/session.rb', line 9 def exit_all=(bool) @@exit_all = bool end |
#exit_all? ⇒ Boolean
6 7 8 |
# File 'lib/irt/session.rb', line 6 def exit_all? @@exit_all end |
#run_file(file_path = IRT.irt_file) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/irt/session.rb', line 58 def run_file(file_path=IRT.irt_file) raise Errno::ENOENT, "No such file or directory - #{file_path}" unless File.exist?(file_path) openfile = proc do @@exit_all = false IRB.conf[:AT_EXIT].pop IRT.init_file(file_path) irb = IRB::Irb.new(nil, IRT.irt_file.to_s) irb.context.irt_mode = :file irb.context.irb_path = IRT.irt_file.to_s irb.context.irb_name = IRT.irt_file.basename IRB.conf[:MAIN_CONTEXT] = irb.context begin catch(:IRB_EXIT) { irb.eval_input } ensure IRB.irb_at_exit end end IRB.conf[:AT_EXIT].push(openfile) @@exit_all = true throw(:IRB_EXIT) ensure unless IRT.cli? IRB.irb_at_exit enter :interactive end end |