Class: RemoteMarshal
- Inherits:
-
Object
- Object
- RemoteMarshal
- Defined in:
- lib/remote_marshal.rb,
lib/remote_marshal/version.rb
Constant Summary collapse
- VERSION =
"0.1.4"
Instance Method Summary collapse
- #eval(&block) ⇒ Object
- #exec!(command) ⇒ Object
- #file(filename) ⇒ Object
-
#initialize(host, user, options) ⇒ RemoteMarshal
constructor
A new instance of RemoteMarshal.
- #test?(name, options) ⇒ Boolean
Constructor Details
#initialize(host, user, options) ⇒ RemoteMarshal
Returns a new instance of RemoteMarshal.
4 5 6 |
# File 'lib/remote_marshal.rb', line 4 def initialize(host, user, ) @ssh = create_ssh(host, user, ) end |
Instance Method Details
#eval(&block) ⇒ Object
8 9 10 11 12 |
# File 'lib/remote_marshal.rb', line 8 def eval(&block) command = block.to_source(strip_enclosure: true) call { |dir| marshal(StringIO.new(command), File.join(dir, token)) } end |
#exec!(command) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/remote_marshal.rb', line 18 def exec!(command) status, output, error = nil, [], [] @ssh.call do |ssh| channel = ssh.open_channel do |chan| chan.exec command do |ch, success| raise command unless success ch.on_data { |_, data| output << data } ch.on_extended_data { |_, _, data| error << data } ch.on_request('exit-status') { |_, data| status = data.read_long } end end channel.wait end [status] + [output, error].map(&:join) end |
#file(filename) ⇒ Object
14 15 16 |
# File 'lib/remote_marshal.rb', line 14 def file(filename) call { |dir| marshal(filename, File.join(dir, File.basename(filename))) } end |
#test?(name, options) ⇒ Boolean
44 45 46 |
# File 'lib/remote_marshal.rb', line 44 def test?(name, ) exec!(%([ #{option} #{name} ])) end |