theine 0.0.9 → 0.0.10.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/theine/client.rb +28 -21
  2. data/lib/theine/worker.rb +11 -21
  3. metadata +5 -5
data/lib/theine/client.rb CHANGED
@@ -7,6 +7,7 @@ class IOUndumpedProxy
7
7
 
8
8
  def initialize(obj)
9
9
  @obj = obj
10
+ create_method_proxies
10
11
  end
11
12
 
12
13
  def completion_proc=(val)
@@ -36,36 +37,42 @@ class IOUndumpedProxy
36
37
  0
37
38
  end
38
39
 
39
- def gets(*args)
40
- @obj.gets(*args)
41
- end
42
-
43
- def puts(*lines)
44
- @obj.puts(*lines)
45
- end
46
-
47
- def print(*objs)
48
- @obj.print(*objs)
49
- end
50
-
51
- def write(data)
52
- @obj.write data
53
- end
54
-
55
40
  def <<(data)
56
41
  @obj << data
57
42
  self
58
43
  end
59
44
 
60
- def flush
61
- @obj.flush
62
- end
63
-
64
45
  # Some versions of Pry expect $stdout or its output objects to respond to
65
46
  # this message.
66
47
  def tty?
67
48
  false
68
49
  end
50
+
51
+ private
52
+ # http://www.ruby-doc.org/core-1.9.3/IO.html
53
+ # Creating method proxies. We take this approach so that method.arity will
54
+ # give the correct result (if we just used *args it would always return -1).
55
+ # Can't use SimpleDelegator, won't work over DRb
56
+ def create_method_proxies
57
+ (@obj.public_methods - public_methods).each do |meth|
58
+ next unless @obj.respond_to?(meth)
59
+ arity = @obj.method(meth).arity
60
+ if arity >= 0
61
+ args = arity.times.map { |i| "a#{i+1}" }
62
+ else
63
+ args = (arity.abs - 1).times.map { |i| "a#{i+1}" }
64
+ args << "*args"
65
+ args = args
66
+ end
67
+ args = (args + ["&block"]).join(", ")
68
+
69
+ singleton_class.class_eval <<-EOS
70
+ def #{meth}(#{args})
71
+ @obj.send(:#{meth}, #{args})
72
+ end
73
+ EOS
74
+ end
75
+ end
69
76
  end
70
77
 
71
78
  module Theine
@@ -119,7 +126,7 @@ module Theine
119
126
  $stderr.puts "\nTheine closed the connection."
120
127
  end
121
128
 
122
- def load_pry_history
129
+ def load_pry_history
123
130
  history_file = File.expand_path("~/.pry_history")
124
131
  if File.exist?(history_file)
125
132
  File.readlines(history_file).pop(100).each do |line|
data/lib/theine/worker.rb CHANGED
@@ -3,34 +3,24 @@ APP_PATH = "#{root_path}/config/application"
3
3
  require "#{root_path}/config/boot"
4
4
  require "#{root_path}/config/environment"
5
5
  require 'drb/drb'
6
+ require 'delegate'
6
7
 
7
8
  $real_stdout = $stdout
8
9
  $real_stderr = $stderr
9
10
 
10
11
  module Theine
11
- class Worker
12
- attr_reader :stdin, :stdout, :stderr
13
- InputProxy = Struct.new :input do
14
- # Reads a line from the input
15
- def readline(prompt)
16
- case readline_arity
17
- when 1 then input.readline(prompt)
18
- else input.readline
19
- end
20
- end
21
-
22
- def completion_proc=(val)
23
- input.completion_proc = val
24
- end
25
-
26
- def readline_arity
27
- input.readline_arity
28
- end
29
-
30
- def gets(*args)
31
- input.gets(*args)
12
+ class InputProxy < SimpleDelegator
13
+ # Reads a line from the input
14
+ def readline(prompt)
15
+ case readline_arity
16
+ when 1 then __getobj__.readline(prompt)
17
+ else __getobj__.readline
32
18
  end
33
19
  end
20
+ end
21
+
22
+ class Worker
23
+ attr_reader :stdin, :stdout, :stderr
34
24
 
35
25
  def initialize
36
26
  @pumps = []
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theine
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.9
4
+ prerelease: 7
5
+ version: 0.0.10.rc1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jan Berdajs
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-02 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -61,9 +61,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '>='
64
+ - - '>'
65
65
  - !ruby/object:Gem::Version
66
- version: '0'
66
+ version: 1.3.1
67
67
  none: false
68
68
  requirements: []
69
69
  rubyforge_project: