Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Binding support. It was so easy.

  • Loading branch information...
commit 5dc55f4620a758b8edc39381cc69a63e10afbbad 1 parent 8b85c76
authored October 16, 2008
2  doc/lc_example.rb
@@ -21,7 +21,7 @@
21 21
 port = port.zero? ? 3333 : port
22 22
 $x = ARGV[1]
23 23
 
24  
-lc = LiveConsole.new :socket, :port => port
  24
+lc = LiveConsole.new :socket, :port => port, :bind => binding
25 25
 lc.start
26 26
 
27 27
 puts "My PID is #{Process.pid}, " \
18  lib/live_console.rb
@@ -17,7 +17,7 @@ class LiveConsole
17 17
 	include Socket::Constants
18 18
 	autoload :IOMethods, 'live_console/io_methods'
19 19
 
20  
-	attr_accessor :io_method, :io, :thread
  20
+	attr_accessor :io_method, :io, :thread, :bind
21 21
 	private :io_method=, :io=, :thread=
22 22
 	
23 23
 	# call-seq:
@@ -28,12 +28,18 @@ class LiveConsole
28 28
 	#	LiveConsole.new(:socket, :port => 3030, :host => '0.0.0.0')
29 29
 	#	# Use a Unix Domain Socket (which is more secure) instead:
30 30
 	#	LiveConsole.new(:unix_socket, :path => '/tmp/my_liveconsole.sock',
31  
-	#	                :mode => 0600)
  31
+	#	                :mode => 0600, :uid => Process.uid, :gid => Process.gid)
  32
+	#	# By default, the mode is 0600, and the uid and gid are those of the 
  33
+	#	# current process.  These three options are for the file's permissions.
  34
+	#	# You can also supply a binding for IRB's toplevel:
  35
+	#	LiveConsole.new(:unix_socket, 
  36
+	#		:path => "/tmp/live_console_#{Process.pid}.sock", :bind => binding)
32 37
 	#
33 38
 	# Creates a new LiveConsole.  You must next call LiveConsole#start when you
34 39
 	# want to spawn the thread to accept connections and start the console.
35 40
 	def initialize(io_method, opts = {})
36 41
 		self.io_method = io_method.to_sym
  42
+		self.bind = opts.delete :bind
37 43
 		unless IOMethods::List.include?(self.io_method)
38 44
 			raise ArgumentError, "Unknown IO method: #{io_method}" 
39 45
 		end
@@ -52,7 +58,7 @@ def start
52 58
 				if io.start
53 59
 					irb_io = GenericIOMethod.new io.raw_input, io.raw_output
54 60
 					begin
55  
-						IRB.start_with_io(irb_io)
  61
+						IRB.start_with_io(irb_io, bind)
56 62
 					rescue Errno::EPIPE => e
57 63
 						io.stop
58 64
 					end
@@ -93,7 +99,7 @@ module IRB
93 99
 	@inited = false
94 100
 
95 101
 	# Overridden a la FXIrb to accomodate our needs.
96  
-	def IRB.start_with_io(io, &block)
  102
+	def IRB.start_with_io(io, bind, &block)
97 103
 		unless @inited
98 104
 			setup '/dev/null'
99 105
 			IRB.parse_opts
@@ -101,7 +107,9 @@ def IRB.start_with_io(io, &block)
101 107
 			@inited = true
102 108
 		end
103 109
 
104  
-		irb = Irb.new(nil, io, io)
  110
+		bind ||= IRB::Frame.top(1)
  111
+		ws = IRB::WorkSpace.new(bind)
  112
+		irb = Irb.new(ws, io, io)
105 113
 
106 114
 		@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
107 115
 		@CONF[:MAIN_CONTEXT] = irb.context

0 notes on commit 5dc55f4

Please sign in to comment.
Something went wrong with that request. Please try again.