Class: Soloist::Remote
- Inherits:
-
Object
- Object
- Soloist::Remote
- Defined in:
- lib/soloist/remote.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
writeonly
Sets the attribute connection.
-
#exitstatus ⇒ Object
readonly
Returns the value of attribute exitstatus.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #backtick(command) ⇒ Object
-
#initialize(user, host, key, options = {}) ⇒ Remote
constructor
A new instance of Remote.
- #system(command) ⇒ Object
- #system!(*command) ⇒ Object
- #upload(from, to, opts = "--exclude .git") ⇒ Object
Constructor Details
#initialize(user, host, key, options = {}) ⇒ Remote
Returns a new instance of Remote.
17 18 19 20 21 22 |
# File 'lib/soloist/remote.rb', line 17 def initialize(user, host, key, = {}) @user = user @host = host @key = key @timeout = [:timeout] || 10000 end |
Instance Attribute Details
#connection=(value) ⇒ Object
Sets the attribute connection
10 11 12 |
# File 'lib/soloist/remote.rb', line 10 def connection=(value) @connection = value end |
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def exitstatus @exitstatus end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def key @key end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def stdout @stdout end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def timeout @timeout end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'lib/soloist/remote.rb', line 9 def user @user end |
Class Method Details
.from_uri(uri, key = "~/.ssh/id_rsa") ⇒ Object
12 13 14 15 |
# File 'lib/soloist/remote.rb', line 12 def self.from_uri(uri, key = "~/.ssh/id_rsa") parsed = URI.parse("ssh://#{uri}") new(parsed.user || Etc.getlogin, parsed.host, key) end |
Instance Method Details
#backtick(command) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/soloist/remote.rb', line 24 def backtick(command) @stdout = "" @stderr = "" exec(command) @stdout end |
#system(command) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/soloist/remote.rb', line 31 def system(command) @stdout = STDOUT @stderr = STDERR exec(command) exitstatus end |
#system!(*command) ⇒ Object
38 39 40 41 42 |
# File 'lib/soloist/remote.rb', line 38 def system!(*command) system(*command).tap do |status| raise RemoteError.new("#{command.join(" ")} exited #{status}") unless status == 0 end end |
#upload(from, to, opts = "--exclude .git") ⇒ Object
44 45 46 |
# File 'lib/soloist/remote.rb', line 44 def upload(from, to, opts = "--exclude .git") Kernel.system("rsync -e 'ssh -i #{key}' -avz --delete #{from} #{user}@#{host}:#{to} #{opts}") end |