pry-bot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ pry-remote - Copyright (c) 2012 - Mon ouïe
2
+
3
+ This software is provided 'as-is', without any express or
4
+ implied warranty. In no event will the authors be held
5
+ liable for any damages arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute
9
+ it freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented;
12
+ you must not claim that you wrote the original software.
13
+ If you use this software in a product, an acknowledgment
14
+ in the product documentation would be appreciated but
15
+ is not required.
16
+
17
+ 2. Altered source versions must be plainly marked as such,
18
+ and must not be misrepresented as being the original software.
19
+
20
+ 3. This notice may not be removed or altered from any
21
+ source distribution.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # What is it?
2
+
3
+ A way to talk to Pry from another application. This is achieved by using DRb to proxy Pry's input and output.
4
+
5
+ # Usage
6
+
7
+ shared_io = DRbObject.new nil, 'druby://:9000'
8
+ result = shared_io.pry_eval input
9
+
10
+ # Thanks
11
+
12
+ This project is heavily influenced by Mon Ouie's Pry Remote.
13
+
data/bin/pry-bot ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pry-bot'
4
+ PryBot::CLI.new.run
data/lib/client.rb ADDED
@@ -0,0 +1,19 @@
1
+ module PryBot
2
+ # A client is used to retrieve information from the client program.
3
+ Client = Struct.new :input, :output, :thread, :stdout, :stderr do
4
+ # Waits until both an input and output are set
5
+ def wait
6
+ sleep 0.01 until input and output and thread
7
+ end
8
+
9
+ # Tells the client the session is terminated
10
+ def kill
11
+ thread.run
12
+ end
13
+
14
+ # @return [InputProxy] Proxy for the input
15
+ def input_proxy
16
+ InputProxy.new input
17
+ end
18
+ end
19
+ end
data/lib/core-ext.rb ADDED
@@ -0,0 +1,20 @@
1
+
2
+ module PryBot
3
+ DefaultHost = "localhost"
4
+ DefaultPort = 9876
5
+ end
6
+
7
+
8
+ class Object
9
+ # Starts a remote Pry session
10
+ #
11
+ # @param [String] host Host of the server
12
+ # @param [Integer] port Port of the server
13
+ def remote_pry(host = PryBot::DefaultHost, port = PryBot::DefaultPort)
14
+ PryBot::Server.run(self)
15
+ end
16
+
17
+ # a handy alias as many people may think the method is named after the gem
18
+ # (pry-remote)
19
+ alias pry_remote remote_pry
20
+ end
@@ -0,0 +1,21 @@
1
+ module PryBot
2
+ # A class to represent an input object created from DRb. This is used because
3
+ # Pry checks for arity to know if a prompt should be passed to the object.
4
+ #
5
+ # @attr [#readline] input Object to proxy
6
+ InputProxy = Struct.new :input do
7
+ # Reads a line from the input
8
+ def readline(prompt)
9
+ case readline_arity
10
+ when 1 then input.readline(prompt)
11
+ else input.readline
12
+ end
13
+ end
14
+
15
+ def readline_arity
16
+ input.method_missing(:method, :readline).arity
17
+ rescue NameError
18
+ 0
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,66 @@
1
+ module PryBot
2
+ # Class used to wrap modules so that they can be sent through DRb. This will
3
+ # mostly be used for Readline.
4
+ class StringIOProxy
5
+ include DRb::DRbUndumped
6
+
7
+ attr_accessor :obj
8
+ def initialize(obj)
9
+ @stdout = $stdout
10
+ @stdin = $stdin
11
+ @obj = obj
12
+ end
13
+
14
+ def completion_proc=(val)
15
+ if @obj.respond_to? :completion_proc=
16
+ @obj.completion_proc = val
17
+ end
18
+ end
19
+
20
+ attr_reader :completion_proc
21
+
22
+ def readline(prompt="")
23
+ begin
24
+ @obj.readline()
25
+ rescue EOFError
26
+ ""
27
+ end
28
+ end
29
+
30
+ def string()
31
+ @obj.string
32
+ end
33
+
34
+ def puts(*lines)
35
+ lines.map! {|line| line.end_with?("\n") ? line : line+"\n" }
36
+ # @stdout.puts "STDOUT: #{lines.inspect}"
37
+ lines.each { |l| self << l}
38
+ end
39
+
40
+ def print(*objs)
41
+ @obj.puts(*objs)
42
+ end
43
+
44
+ def write(data)
45
+ @obj.write data
46
+ end
47
+
48
+ def <<(data)
49
+ @obj.string << data
50
+ self
51
+ end
52
+
53
+ def tty?
54
+ false
55
+ end
56
+
57
+ def readlines
58
+ pos = @obj.pos
59
+ string = @obj.string[pos..-1]
60
+ @obj.pos = @obj.size
61
+ return string
62
+ end
63
+
64
+ end
65
+
66
+ end
data/lib/pry-bot.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'pry'
2
+ require 'drb'
3
+ require 'readline'
4
+ require 'open3'
5
+
6
+ require 'client'
7
+ require 'core-ext'
8
+ require 'shared-io'
9
+ require 'input-proxy'
10
+ require 'io-string-proxy'
11
+ require 'server'
12
+ require 'system'
13
+
data/lib/server.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'pry-bot'
2
+ require 'drb'
3
+
4
+ module PryBot
5
+ class Server
6
+ def self.run(object)
7
+ shared_io = PryBot::SharedIO.new
8
+ DRb.start_service 'druby://:9000', shared_io
9
+
10
+ # Startup PRY
11
+ Pry.color = false
12
+ Pry.pager = false
13
+ pry = Pry.start(object, :input => shared_io.input_proxy, :output => shared_io.output_proxy)
14
+
15
+ # Kill PRY
16
+ DRb.thread.join
17
+ trap("INT") { DRb.stop_service }
18
+ end
19
+ end
20
+ end
data/lib/shared-io.rb ADDED
@@ -0,0 +1,19 @@
1
+ module PryBot
2
+ class SharedIO
3
+ attr_accessor :input_proxy, :output_proxy
4
+
5
+ def initialize
6
+ @input = StringIO.new
7
+ @output = StringIO.new
8
+
9
+ @input_proxy = PryBot::StringIOProxy.new(@input)
10
+ @output_proxy = PryBot::StringIOProxy.new(@output)
11
+ end
12
+
13
+ def pry_eval(string)
14
+ @input_proxy << string
15
+ sleep 0.1
16
+ @output_proxy.readlines
17
+ end
18
+ end
19
+ end
data/lib/system.rb ADDED
@@ -0,0 +1,25 @@
1
+ module PryBot
2
+ # Ensure that system (shell command) output is redirected for remote session.
3
+ System = proc do |output, cmd, _|
4
+
5
+ status = nil
6
+ Open3.popen3 cmd do |stdin, stdout, stderr, wait_thr|
7
+ stdin.close # Send EOF to the process
8
+
9
+ until stdout.eof? and stderr.eof?
10
+ if res = IO.select([stdout, stderr])
11
+ res[0].each do |io|
12
+ next if io.eof?
13
+ output.write io.read_nonblock(1024)
14
+ end
15
+ end
16
+ end
17
+
18
+ status = wait_thr.value
19
+ end
20
+
21
+ unless status.success?
22
+ output.puts "Error while executing command: #{cmd}"
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Laster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ description: Connect to Pry remotely using DRb
31
+ email: jason.laster.11@gmail.com
32
+ executables:
33
+ - pry-bot
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/client.rb
38
+ - lib/core-ext.rb
39
+ - lib/input-proxy.rb
40
+ - lib/io-string-proxy.rb
41
+ - lib/pry-bot.rb
42
+ - lib/server.rb
43
+ - lib/shared-io.rb
44
+ - lib/system.rb
45
+ - README.md
46
+ - LICENSE
47
+ - bin/pry-bot
48
+ homepage: http://github.com/JasonLaster/pry-bot
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Talk to Pry programatically
72
+ test_files: []
73
+ has_rdoc: