net-ssh-simple 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +68 -0
  2. data/lib/net/ssh/simple/version.rb +1 -1
  3. metadata +17 -17
@@ -25,6 +25,10 @@ synchronously or asynchronously.
25
25
 
26
26
  == Examples
27
27
 
28
+ Note: If you are reading this on github then {click here}[http://rubydoc.info/gems/net-ssh-simple/file/README.rdoc] for a more readable
29
+ version with syntax highlighting.
30
+
31
+
28
32
  === Block Syntax (synchronous)
29
33
 
30
34
  require 'net/ssh/simple'
@@ -65,6 +69,70 @@ synchronously or asynchronously.
65
69
  s.scp_dl 'example3.com', '/tmp/remote_foo', '/tmp/local_bar'
66
70
  s.close
67
71
 
72
+ == Thread safety
73
+
74
+ Do _not_ share a Net::SSH::Simple instance across threads.
75
+
76
+ That's the only rule to watch out for. Other than that you're
77
+ free to use Net::SSH::Simple concurrently in different Threads.
78
+
79
+ If you want to use the instance syntax in a threaded environment
80
+ then the following idiom will provide the best performance:
81
+
82
+ require 'net/ssh/simple'
83
+
84
+ # Create and re-use one instance per thread, with a default username.
85
+ def ss
86
+ Thread.current[:simplessh] ||= Net::SSH::Simple.new({:user => 'bob'})
87
+ end
88
+
89
+ # Strictly optional. You may use this method to close the
90
+ # SSH connections early. Otherwise our instance will tear
91
+ # down automatically when the enclosing thread finishes.
92
+ def ss_close
93
+ ss.close
94
+ Thread.current[:simplessh] = nil
95
+ end
96
+
97
+ # By sharing the same Net::SSH::Simple instance across calls
98
+ # to this method our ssh transport connections get re-used
99
+ # when the same remote host is accessed multiple times.
100
+ def do_something_involving_ssh
101
+ # The connections to example1-5.com are re-used across
102
+ # multiple calls to this method.
103
+ ss.ssh 'example1.com', 'echo "Hello World."', {:user => 'not_bob'}
104
+ ss.scp_ul 'example2.com', '/tmp/local_foo', '/tmp/remote_bar'
105
+ ss.scp_dl 'example3.com', '/tmp/remote_foo', '/tmp/local_bar'
106
+
107
+ t = ss.async do
108
+ scp_ul 'example4.com', '/tmp/local_foo', '/tmp/remote_bar'
109
+ end
110
+
111
+ ss.sync do
112
+ scp_ul 'example5.com', '/tmp/local_foo', '/tmp/remote_bar'
113
+ end
114
+
115
+ # wait for our async call to finish
116
+ t.value
117
+
118
+ # Below we explicitly do _not_ use the shared instance
119
+ # because we want these connections to close immediately
120
+ # after the block finishes. This is useful when you know
121
+ # that some hosts will be connected to only once during
122
+ # the lifetime of a thread (there's no point in keeping
123
+ # these open).
124
+ Net::SSH::Simple.sync do
125
+ # opens connections to example8.com, example9.com
126
+ ssh 'example8.com', 'echo "Hello World."'
127
+ ssh 'example9.com', 'echo "Hello World."'
128
+
129
+ # connections are reused
130
+ ssh 'example8.com', 'echo "World Hello."'
131
+ ssh 'example9.com', 'echo "World Hello."'
132
+
133
+ # both connections close at the end of this block
134
+ end
135
+ end
68
136
 
69
137
  == Documentation
70
138
 
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  module SSH
3
3
  class Simple
4
- VERSION = "1.5.3"
4
+ VERSION = "1.5.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ssh-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-03 00:00:00.000000000Z
12
+ date: 2012-04-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
16
- requirement: &18901260 !ruby/object:Gem::Requirement
16
+ requirement: &17323340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18901260
24
+ version_requirements: *17323340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: net-scp
27
- requirement: &18900420 !ruby/object:Gem::Requirement
27
+ requirement: &17322560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18900420
35
+ version_requirements: *17322560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: blockenspiel
38
- requirement: &18899400 !ruby/object:Gem::Requirement
38
+ requirement: &17321620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.4.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *18899400
46
+ version_requirements: *17321620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hashie
49
- requirement: &18896720 !ruby/object:Gem::Requirement
49
+ requirement: &17320880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *18896720
57
+ version_requirements: *17320880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &18895020 !ruby/object:Gem::Requirement
60
+ requirement: &17317060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.2.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *18895020
68
+ version_requirements: *17317060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &18893060 !ruby/object:Gem::Requirement
71
+ requirement: &17316460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *18893060
79
+ version_requirements: *17316460
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cover_me
82
- requirement: &18892280 !ruby/object:Gem::Requirement
82
+ requirement: &17315240 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *18892280
90
+ version_requirements: *17315240
91
91
  description: Net::SSH::Simple is a simple wrapper around Net::SSH and Net::SCP.
92
92
  email:
93
93
  - moe@busyloop.net
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: -2495961166063881363
126
+ hash: -4150931459409160842
127
127
  requirements: []
128
128
  rubyforge_project:
129
129
  rubygems_version: 1.8.10