mame-rirb 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ === 0.10 / 2008-10-22
2
+
3
+ * first release.
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/rirb
6
+ lib/rirb.rb
7
+ lib/rirb/remote-irb.rb
@@ -0,0 +1,71 @@
1
+ = rirb
2
+
3
+ * http://github.com/mame/rirb/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ rirb (remote irb) allows you to attach a running ruby process and
8
+ to observe/modify global states via an irb prompt.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+
13
+ == SYNOPSIS:
14
+
15
+ First, you should add -rrirb option for a target process:
16
+
17
+ terminal 1:
18
+ $ cat test.rb
19
+ $i = 0
20
+ loop do
21
+ p $i
22
+ $i += 1
23
+ sleep 10
24
+ end
25
+
26
+ $ ruby -rrirb test.rb
27
+ 0
28
+ 1
29
+ 2
30
+
31
+ you then run rirb in the same directory on another terminal and
32
+ get irb prompt:
33
+
34
+ terminal 2:
35
+ $ rirb
36
+ irb(main):001:0>
37
+
38
+ You can observe global states:
39
+
40
+ terminal 2:
41
+ irb(main):001:0> p $i
42
+ 2
43
+ => nil
44
+
45
+ You can also modify:
46
+
47
+ terminal 2:
48
+ irb(main):002:0> $i = 100
49
+
50
+ terminal 1:
51
+ $ ruby -rrirb test.rb
52
+ 0
53
+ 1
54
+ 2
55
+ 100
56
+ 101
57
+ 102
58
+
59
+
60
+ == REQUIREMENTS:
61
+
62
+ None
63
+
64
+ == INSTALL:
65
+
66
+ * gem install mame-rirb
67
+
68
+ == LICENSE:
69
+
70
+ Copyright:: Yusuke Endoh <mame@tsg.ne.jp>
71
+ License:: Ruby's
@@ -0,0 +1,11 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.new('rirb', "0.10") do |p|
7
+ p.rubyforge_name = 'rirb' # if different than lowercase project name
8
+ p.developer('Yusuke Endoh', 'mame@tsg.ne.jp')
9
+ end
10
+
11
+ # vim: syntax=ruby
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "socket"
4
+ require "optparse"
5
+ require "yaml"
6
+
7
+ def error(msg)
8
+ $stderr.puts msg
9
+ exit 1
10
+ end
11
+
12
+ def load_rirb(file)
13
+ h = YAML.load_file(file)
14
+ case h["type"]
15
+ when "unix"
16
+ UNIXSocket.open(h["path"]) {|sock| yield sock }
17
+ else
18
+ error("unknown communication type")
19
+ end
20
+ end
21
+
22
+ def option(argv)
23
+ file = nil
24
+ until argv.empty?
25
+ arg = argv.shift
26
+ if arg == "-h"
27
+ puts "usage: rirb [RIRB_FILE]"
28
+ exit 0
29
+ end
30
+ error("cannot read #{ arg }") unless File.readable?(arg)
31
+ file = arg
32
+ end
33
+ unless file
34
+ file = Dir.glob("*.rirb").sort.first
35
+ end
36
+ file
37
+ end
38
+
39
+ load_rirb(option(ARGV.dup)) do |sock|
40
+ loop do
41
+ ios, = select([sock, $stdin])
42
+ if ios.include?($stdin)
43
+ break if $stdin.eof?
44
+ sock.write($stdin.readpartial(1024))
45
+ sock.flush
46
+ end
47
+ if ios.include?(sock)
48
+ break if sock.eof?
49
+ $stdout.write(sock.readpartial(1024))
50
+ $stdout.flush
51
+ end
52
+ end
53
+ end
54
+
55
+ # vim: syntax=ruby
@@ -0,0 +1,39 @@
1
+ require "socket"
2
+ require "tmpdir"
3
+
4
+ rirb_file = (ENV["RIRB_INFO_FILE"] || "$0-$$.rirb").gsub(/\$./) {|v| eval(v) }
5
+ rirb_sock = File.join(Dir.tmpdir, "rirb.#{ $$ }")
6
+
7
+ open(rirb_file, "w") do |f|
8
+ f.puts "type: unix"
9
+ f.puts "path: #{ rirb_sock }"
10
+ end
11
+
12
+ at_exit do
13
+ begin; File.unlink(rirb_file); rescue Exception; end
14
+ begin; File.unlink(rirb_sock); rescue Exception; end
15
+ end
16
+
17
+ start = false
18
+ Thread.abort_on_exception = true
19
+ Thread.new do
20
+ UNIXServer.open(rirb_sock) do |serv|
21
+ start = true
22
+ first = true
23
+ while sock = serv.accept
24
+ if first
25
+ require "irb"
26
+ argv = ARGV.dup
27
+ ARGV.clear
28
+ IRB.setup(nil)
29
+ require "rirb/remote-irb"
30
+ ARGV.replace(argv)
31
+ first = false
32
+ end
33
+ IRB.rirb(sock)
34
+ sock.close
35
+ end
36
+ end
37
+ end
38
+
39
+ nil until start
@@ -0,0 +1,65 @@
1
+ require "irb"
2
+
3
+ module IRB
4
+ class RemoteInputMethod < StdioInputMethod
5
+ def initialize(io)
6
+ super()
7
+ @io = io
8
+ @line = []
9
+ end
10
+ def gets
11
+ @io.print @prompt
12
+ line = @io.gets
13
+ @line << line
14
+ line
15
+ end
16
+ def eof?
17
+ @io.eof?
18
+ end
19
+ def line(line_no)
20
+ @line[line_no]
21
+ end
22
+ end
23
+
24
+ class RemoteOutputMethod < OutputMethod
25
+ def initialize(io)
26
+ @io = io
27
+ end
28
+ def print(*opts)
29
+ @io.print(*opts)
30
+ end
31
+ end
32
+
33
+ class Irb
34
+ def print(*args)
35
+ @@rirb_io.print(*args)
36
+ end
37
+ def printf(*args)
38
+ @@rirb_io.printf(*args)
39
+ end
40
+ end
41
+
42
+ top = TOPLEVEL_BINDING.eval("self")
43
+ def top.to_s
44
+ "rirb:" + $0
45
+ end
46
+ def top.rp(*args)
47
+ args.each {|a| Irb.class_eval("@@rirb_io").puts a.inspect }
48
+ args.size == 0 ? nil : args.size == 1 ? args.first : args
49
+ end
50
+
51
+ def IRB.rirb(io)
52
+ im = RemoteInputMethod.new(io)
53
+ om = RemoteOutputMethod.new(io)
54
+ Irb.class_eval("@@rirb_io = io")
55
+ irb = Irb.new(nil, im, om)
56
+
57
+ @CONF[:MAIN_CONTEXT] = irb.context
58
+ @CONF[:PROMPT_MODE] = :DEFAULT
59
+ catch(:IRB_EXIT) { irb.eval_input }
60
+
61
+ rescue Exception
62
+ ensure
63
+ Irb.class_eval { remove_class_variable(:@@rirb_io) } rescue nil
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mame-rirb
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.10"
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Endoh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-22 00:00:00 -07:00
13
+ default_executable: rirb
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.0
23
+ version:
24
+ description: rirb (remote irb) allows you to attach a running ruby process and to observe/modify global states via an irb prompt.
25
+ email:
26
+ - mame@tsg.ne.jp
27
+ executables:
28
+ - rirb
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - bin/rirb
41
+ - lib/rirb.rb
42
+ - lib/rirb/remote-irb.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/mame/rirb/tree/master
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: rirb
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: rirb (remote irb) allows you to attach a running ruby process and to observe/modify global states via an irb prompt.
70
+ test_files: []
71
+