thor-ssh 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'thor-ssh/remote_file'
2
+ require 'thor-ssh/remote_server'
2
3
  require 'thor-ssh/actions/empty_directory'
3
4
  require 'thor-ssh/actions/create_file'
4
5
  require 'thor-ssh/actions/create_link'
@@ -9,13 +10,13 @@ module ThorSsh
9
10
  module Actions
10
11
 
11
12
  # Returns a connection to the destination server for this thor class.
12
- def destination_server
13
- @destination_server
13
+ def destination_connection
14
+ @destination_connection
14
15
  end
15
16
 
16
- # Sets the destination server connection
17
- def destination_server=(val)
18
- @destination_server = val
17
+ # Sets the connection to the destination server
18
+ def destination_connection=(val)
19
+ @destination_connection = val
19
20
  end
20
21
 
21
22
  # Returns a remote file or File object that can used to query
@@ -23,12 +24,19 @@ module ThorSsh
23
24
  # it is assumed to be local and a normal File class is returned
24
25
  def destination_files
25
26
  if self.destination_server
26
- return @destination_files ||= RemoteFile.new(self.destination_server)
27
+ return @destination_files ||= RemoteFile.new(self.destination_connection)
27
28
  else
28
29
  return File
29
30
  end
30
31
  end
31
32
 
33
+ # Returns a remote file or File object that can used to query
34
+ # or change the state of files. If there is no destination_server
35
+ # it is assumed to be local and a normal File class is returned
36
+ def destination_server
37
+ return @destination_server ||= RemoteServer.new(self.destination_connection)
38
+ end
39
+
32
40
  def inside(dir='', config={}, &block)
33
41
  raise "inside is not implemented in thor-ssh, please use full paths"
34
42
  end
@@ -48,7 +56,7 @@ module ThorSsh
48
56
 
49
57
  unless options[:pretend]
50
58
  # config[:capture] ? `#{command}` : system("#{command}")
51
- return destination_files.run(command)
59
+ return destination_server.run(command)
52
60
  end
53
61
  end
54
62
 
@@ -0,0 +1,17 @@
1
+ require 'net/ssh'
2
+ require 'net/sftp'
3
+
4
+ module ThorSsh
5
+ class RemoteServer
6
+ attr_reader :connection
7
+
8
+ def initialize(connection)
9
+ @connection = connection
10
+ end
11
+
12
+ def run(command)
13
+ return connection.exec!(command)
14
+ end
15
+
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ThorSsh
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/spec/actions_spec.rb CHANGED
@@ -7,22 +7,22 @@ describe ThorSsh do
7
7
  before do
8
8
  # Setup the test and connect to a test server
9
9
  @thor_test = ThorTest.new
10
- @thor_test.destination_server = VagrantManager.connect
11
- # @thor_test.destination_server = Net::SSH.start('localhost', 'ubuntu', :port => 2222)
10
+ @thor_test.destination_connection = VagrantManager.connect
12
11
  end
13
12
 
14
13
  after do
15
14
  # Close the connection
16
- @thor_test.destination_server.close
15
+ @thor_test.destination_connection.close
17
16
  end
18
17
 
19
18
  before(:all) do
20
19
  @base_path = '/home/vagrant/thortest'
21
20
 
22
21
  @thor_test = ThorTest.new
23
- @thor_test.destination_server = VagrantManager.connect
22
+ @thor_test.destination_connection = VagrantManager.connect
24
23
  @thor_test.destination_files.rm_rf(@base_path)
25
- @thor_test.destination_server.close
24
+ @thor_test.destination_connection.close
25
+
26
26
  end
27
27
 
28
28
  it 'should create an empty directory' do
@@ -47,13 +47,14 @@ describe ThorSsh do
47
47
  end
48
48
 
49
49
  def mode(path)
50
- ls = @thor_test.destination_files.run("ls -lh \"#{@base_path}/#{path}\"")
50
+ ls = @thor_test.destination_server.run("ls -lh \"#{@base_path}/#{path}\"")
51
51
  mode = ls.strip.split(/ /).first.strip
52
52
  return mode
53
53
  end
54
54
 
55
55
  it "should set the mode" do
56
56
  @thor_test.create_file("#{@base_path}/modeFile", "More awesome content")
57
+ @thor_test.chmod("#{@base_path}/modeFile", 0644)
57
58
  mode('modeFile').should == '-rw-r--r--'
58
59
  @thor_test.chmod("#{@base_path}/modeFile", 0600)
59
60
  mode('modeFile').should == '-rw-------'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -144,6 +144,7 @@ files:
144
144
  - lib/thor-ssh/actions/file_manipulation.rb
145
145
  - lib/thor-ssh/actions/inject_into_file.rb
146
146
  - lib/thor-ssh/remote_file.rb
147
+ - lib/thor-ssh/remote_server.rb
147
148
  - lib/thor-ssh/version.rb
148
149
  - spec/actions_spec.rb
149
150
  - spec/remote_file_spec.rb
@@ -169,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  segments:
171
172
  - 0
172
- hash: -1300273360678236015
173
+ hash: -3815866701832875741
173
174
  required_rubygems_version: !ruby/object:Gem::Requirement
174
175
  none: false
175
176
  requirements:
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  version: '0'
179
180
  segments:
180
181
  - 0
181
- hash: -1300273360678236015
182
+ hash: -3815866701832875741
182
183
  requirements: []
183
184
  rubyforge_project:
184
185
  rubygems_version: 1.8.22