Module: ThorSsh::Actions
- Defined in:
- lib/thor-ssh/actions.rb
Instance Method Summary collapse
- #as_root(options = {}) ⇒ Object
-
#as_user(username, options = {}) ⇒ Object
As user takes a block and runs the code inside the block as the specified user.
-
#destination_connection ⇒ Object
Returns a connection to the destination server for this thor class.
-
#destination_connection=(val) ⇒ Object
Sets the connection to the destination server.
-
#destination_files ⇒ Object
Returns a remote file or File object that can used to query or change the state of files.
-
#destination_server ⇒ Object
Returns a RemoteServer instance or a LocalServer instance.
-
#exec(command, options = {}) ⇒ Object
Similar to run, but silent and always executes on the remote server.
- #inside(dir = '', config = {}, &block) ⇒ Object
- #run(command, options = {}, config = {}) ⇒ Object
-
#run_as_user ⇒ Object
The user commands should be run as as the moment.
Instance Method Details
#as_root(options = {}) ⇒ Object
63 64 65 66 67 |
# File 'lib/thor-ssh/actions.rb', line 63 def as_root(={}) as_user('root', ) do yield end end |
#as_user(username, options = {}) ⇒ Object
As user takes a block and runs the code inside the block as the specified user. All actions are run as the user
Parameters
- username<String>
-
Who to run as
- options<String>
-
A hash of options for how to get to this user
Options
:shell - Boolean, should this be invoked in the shell for the user
56 57 58 59 60 61 |
# File 'lib/thor-ssh/actions.rb', line 56 def as_user(username, ={}) old_run_as_user = @run_as_user @run_as_user = username yield @run_as_user = old_run_as_user end |
#destination_connection ⇒ Object
Returns a connection to the destination server for this thor class.
15 16 17 |
# File 'lib/thor-ssh/actions.rb', line 15 def destination_connection @destination_connection end |
#destination_connection=(val) ⇒ Object
Sets the connection to the destination server
20 21 22 |
# File 'lib/thor-ssh/actions.rb', line 20 def destination_connection=(val) @destination_connection = val end |
#destination_files ⇒ Object
Returns a remote file or File object that can used to query or change the state of files. If there is no destination_server it is assumed to be local and a normal File class is returned
27 28 29 30 31 32 33 |
# File 'lib/thor-ssh/actions.rb', line 27 def destination_files if self.destination_connection return @destination_files ||= RemoteFile.new(self, self.destination_connection) else return @destination_files ||= LocalFile.new(self) end end |
#destination_server ⇒ Object
Returns a RemoteServer instance or a LocalServer instance. Makes it so calls to run events can be called the same reguardless of the destination.
38 39 40 41 42 43 44 |
# File 'lib/thor-ssh/actions.rb', line 38 def destination_server if self.destination_connection return @destination_server ||= RemoteServer.new(self, self.destination_connection) else return @destination_server ||= LocalServer.new(self) end end |
#exec(command, options = {}) ⇒ Object
Similar to run, but silent and always executes on the remote server
79 80 81 |
# File 'lib/thor-ssh/actions.rb', line 79 def exec(command, ={}) return destination_server.run(command, ) end |
#inside(dir = '', config = {}, &block) ⇒ Object
74 75 76 |
# File 'lib/thor-ssh/actions.rb', line 74 def inside(dir='', config={}, &block) raise "inside is not implemented in thor-ssh, please use full paths" end |
#run(command, options = {}, config = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/thor-ssh/actions.rb', line 83 def run(command, ={}, config={}) return unless behavior == :invoke destination = relative_to_original_destination_root(destination_root, false) if config[:with] desc = "#{File.basename(config[:with].to_s)} #{desc}" command = "#{config[:with]} #{command}" end say_status :run, command, config.fetch(:verbose, true) unless [:pretend] # config[:capture] ? `#{command}` : system("#{command}") return exec(command, ) end end |
#run_as_user ⇒ Object
The user commands should be run as as the moment
70 71 72 |
# File 'lib/thor-ssh/actions.rb', line 70 def run_as_user @run_as_user end |