em-ssh 0.3.2 → 0.4.0

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.
Files changed (3) hide show
  1. data/lib/em-ssh/shell.rb +19 -12
  2. data/lib/em-ssh/version.rb +1 -1
  3. metadata +3 -3
data/lib/em-ssh/shell.rb CHANGED
@@ -31,7 +31,9 @@ module EventMachine
31
31
  TIMEOUT = 15
32
32
  # @return [Net::SSH::Connection::Channel] The shell to which we can send_data
33
33
  attr_reader :shell
34
- # @return [Net::SSH::Connection]
34
+ # @return [EM::Ssh::Session]
35
+ attr_reader :session
36
+ # @return [EM::Ssh::Connection]
35
37
  attr_reader :connection
36
38
  # @return [Hash] the options passed to initialize
37
39
  attr_reader :options
@@ -70,7 +72,7 @@ module EventMachine
70
72
  @pass = pass
71
73
  @options = opts
72
74
  @connect_opts = {:password => pass, :port => 22, :auth_methods => ['publickey', 'password']}.merge(opts[:net_ssh] || {})
73
- @connection = opts[:connection]
75
+ @session = opts[:session]
74
76
  @parent = opts[:parent]
75
77
  @children = []
76
78
  @reconnect = opts[:reconnect]
@@ -93,12 +95,12 @@ module EventMachine
93
95
  # Disconnected shells cannot be split.
94
96
  def disconnect
95
97
  close
96
- connection && connection.close
98
+ session && session.close
97
99
  end
98
100
 
99
- # @return [Boolean] true if the connection is still alive
101
+ # @return [Boolean] true if the session is still alive
100
102
  def connected?
101
- connection && !connection.closed?
103
+ session && !session.closed?
102
104
  end
103
105
 
104
106
  # Close this shell and all children.
@@ -230,7 +232,7 @@ module EventMachine
230
232
 
231
233
  begin
232
234
  connect
233
- connection.open_channel do |channel|
235
+ session.open_channel do |channel|
234
236
  debug "**** channel open: #{channel}"
235
237
  channel.request_pty(options[:pty] || {}) do |pty,suc|
236
238
  debug "***** pty open: #{pty}; suc: #{suc}"
@@ -244,7 +246,7 @@ module EventMachine
244
246
  @shell.on_data do |ch,data|
245
247
  @buffer += data
246
248
  debug("data: #{@buffer.dump}")
247
- fire(:data)
249
+ fire(:data, data)
248
250
  end
249
251
  Fiber.new { yield(self) if block_given? }.resume
250
252
  f.resume(self)
@@ -266,7 +268,7 @@ module EventMachine
266
268
  # @return [Shell] child
267
269
  def split
268
270
  connect unless connected?
269
- child = self.class.new(host, user, pass, {:connection => connection, :parent => self}.merge(options))
271
+ child = self.class.new(host, user, pass, {:session => session, :parent => self}.merge(options))
270
272
  child.line_terminator = line_terminator
271
273
  children.push(child)
272
274
  child.on(:closed) do
@@ -281,12 +283,13 @@ module EventMachine
281
283
  # Does not open the shell; use #open or #split
282
284
  # You generally won't need to call this on your own.
283
285
  def connect
284
- return @connection if connected?
286
+ return @session if connected?
285
287
  trace = caller
286
288
  f = Fiber.current
287
289
  ::EM::Ssh.start(host, user, connect_opts) do |connection|
290
+ @connection = connection
288
291
  connection.callback do |ssh|
289
- f.resume(@connection = ssh)
292
+ f.resume(@session = ssh)
290
293
  end
291
294
  connection.errback do |e|
292
295
  e.set_backtrace(trace + Array(e.backtrace))
@@ -301,8 +304,12 @@ module EventMachine
301
304
  # You generally don't need to call this.
302
305
  # @see #send_and_wait
303
306
  # @param [String] d the data to send encoded as a string
304
- def send_data(d)
305
- shell.send_data("#{d}#{line_terminator}")
307
+ def send_data(d, send_newline=true)
308
+ if send_newline
309
+ shell.send_data("#{d}#{line_terminator}")
310
+ else
311
+ shell.send_data("#{d}")
312
+ end
306
313
  end
307
314
 
308
315
 
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  class Ssh
3
- VERSION='0.3.2'
3
+ VERSION='0.4.0'
4
4
  end # class::Ssh
5
5
  end # module::EventMachine
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: 1.3.6
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 1.8.21
121
+ rubygems_version: 1.8.24
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: An EventMachine compatible net-ssh