Class: Reservoir::Caller

Inherits:
Object
  • Object
show all
Defined in:
lib/reservoir/caller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Caller

Returns a new instance of Caller.



7
8
9
10
11
12
# File 'lib/reservoir/caller.rb', line 7

def initialize(data = {})
  @remote_user = data[:remote_user]
  @remote_server = data[:remote_server]
  @command = data[:command]
  @success = false
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/reservoir/caller.rb', line 5

def command
  @command
end

#remote_serverObject

Returns the value of attribute remote_server.



5
6
7
# File 'lib/reservoir/caller.rb', line 5

def remote_server
  @remote_server
end

#remote_userObject

Returns the value of attribute remote_user.



5
6
7
# File 'lib/reservoir/caller.rb', line 5

def remote_user
  @remote_user
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/reservoir/caller.rb', line 5

def response
  @response
end

Class Method Details

.exec(full_command) ⇒ Object



47
48
49
# File 'lib/reservoir/caller.rb', line 47

def self.exec(full_command)
  `#{full_command}`
end

Instance Method Details

#full_commandObject



41
42
43
44
45
# File 'lib/reservoir/caller.rb', line 41

def full_command
  return nil if @command.nil?
  return @command if @remote_server.nil?
  "#{ssh} '#{@command}'"
end

#go(command = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/reservoir/caller.rb', line 18

def go(command = nil)
  begin
    @command = command unless command.nil?
    @response = Caller.exec(full_command).strip
    @success = true
  rescue
    @response = "#{$!}"
    @success = false
  end
  @success
end

#go_with_response(command = nil) ⇒ Object



30
31
32
33
# File 'lib/reservoir/caller.rb', line 30

def go_with_response(command = nil)
  go(command)
  @response
end

#sshObject



35
36
37
38
39
# File 'lib/reservoir/caller.rb', line 35

def ssh
  return nil if @remote_server.nil?
  return "ssh #{@remote_server}" if @remote_user.nil?
  "ssh #{@remote_user}@#{@remote_server}"
end

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/reservoir/caller.rb', line 14

def success?
  @success
end