net-ssh-session 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -71,6 +71,10 @@ session.run_multiple(
71
71
  'rake test'
72
72
  )
73
73
 
74
+ # Execute by calling a method
75
+ session.ping("-c 5", "google.com")
76
+ session.df('-h')
77
+
74
78
  # Execute as sudo
75
79
  session.sudo("whoami")
76
80
 
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  module SSH
3
3
  class Session
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
6
6
  end
7
7
  end
@@ -133,6 +133,10 @@ module Net
133
133
  history.last
134
134
  end
135
135
 
136
+ def method_missing(name, *args)
137
+ run("#{name} #{args.join(' ')}".strip)
138
+ end
139
+
136
140
  private
137
141
 
138
142
  def establish_connection
@@ -37,6 +37,19 @@ module Net
37
37
  def to_s
38
38
  "[#{command}] => #{exit_code}, #{output.to_s.bytesize} bytes, #{duration} seconds"
39
39
  end
40
+
41
+ # Get command hash representation
42
+ # @return [Hash]
43
+ def to_hash
44
+ {
45
+ 'command' => command,
46
+ 'output' => output,
47
+ 'exit_code' => exit_code,
48
+ 'start_time' => start_time,
49
+ 'finish_time' => finish_time,
50
+ 'duration' => duration
51
+ }
52
+ end
40
53
  end
41
54
  end
42
55
  end
@@ -58,4 +58,14 @@ describe Net::SSH::SessionCommand do
58
58
  cmd.to_s.should eq("[cmd] => 0, 6 bytes, 1.234 seconds")
59
59
  end
60
60
  end
61
+
62
+ describe '#to_hash' do
63
+ it 'returns command hash representation' do
64
+ cmd = Net::SSH::SessionCommand.new('cmd', 'output', '0', 1.234)
65
+ hash = cmd.to_hash
66
+
67
+ hash.should include 'command', 'output', 'exit_code'
68
+ hash.should include 'start_time', 'finish_time', 'duration'
69
+ end
70
+ end
61
71
  end
data/spec/session_spec.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Net::SSH::Session do
4
- # TODO
4
+ describe '#method_missing' do
5
+ let(:session) { Net::SSH::Session.new('host', 'user', 'password') }
6
+
7
+ it 'runs a command based on missing method name' do
8
+ session.stub(:run).with("uname").and_return(fake_run("uname", "Linux"))
9
+ session.uname.output.should eq("Linux")
10
+ end
11
+ end
5
12
  end
metadata CHANGED
@@ -1,87 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: net-ssh-session
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.1.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dan Sosedoff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-01-22 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
17
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
33
19
  none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '2.11'
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
38
24
  type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
39
28
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
31
+ requirements:
43
32
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '2.11'
46
- - !ruby/object:Gem::Dependency
47
- name: simplecov
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '0.4'
33
+ - !ruby/object:Gem::Version
34
+ version: "2.11"
54
35
  type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: simplecov
55
39
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
42
+ requirements:
59
43
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '0.4'
62
- - !ruby/object:Gem::Dependency
44
+ - !ruby/object:Gem::Version
45
+ version: "0.4"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
63
49
  name: net-ssh
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '2.6'
70
- type: :runtime
71
50
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
73
52
  none: false
74
- requirements:
53
+ requirements:
75
54
  - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '2.6'
55
+ - !ruby/object:Gem::Version
56
+ version: "2.6"
57
+ type: :runtime
58
+ version_requirements: *id004
78
59
  description: Shell interface with helper methods to work with Net::SSH connections
79
- email:
60
+ email:
80
61
  - dan.sosedoff@gmail.com
81
62
  executables: []
63
+
82
64
  extensions: []
65
+
83
66
  extra_rdoc_files: []
84
- files:
67
+
68
+ files:
85
69
  - .gitignore
86
70
  - .rspec
87
71
  - .travis.yml
@@ -105,31 +89,35 @@ files:
105
89
  - spec/spec_helper.rb
106
90
  homepage: https://github.com/sosedoff/net-ssh-session
107
91
  licenses: []
92
+
108
93
  post_install_message:
109
94
  rdoc_options: []
110
- require_paths:
95
+
96
+ require_paths:
111
97
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
98
+ required_ruby_version: !ruby/object:Gem::Requirement
113
99
  none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
105
  none: false
120
- requirements:
121
- - - ! '>='
122
- - !ruby/object:Gem::Version
123
- version: '0'
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: "0"
124
110
  requirements: []
111
+
125
112
  rubyforge_project:
126
113
  rubygems_version: 1.8.24
127
114
  signing_key:
128
115
  specification_version: 3
129
116
  summary: Shell session for Net::SSH connections
130
- test_files:
117
+ test_files:
131
118
  - spec/fixtures/.gitkeep
132
119
  - spec/session_command_spec.rb
133
120
  - spec/session_helpers_spec.rb
134
121
  - spec/session_spec.rb
135
122
  - spec/spec_helper.rb
123
+ has_rdoc: