Class: Minionizer::Session
- Inherits:
-
Object
- Object
- Minionizer::Session
- Defined in:
- lib/minionizer/session.rb
Instance Attribute Summary collapse
-
#command_executor ⇒ Object
readonly
Returns the value of attribute command_executor.
-
#minion ⇒ Object
readonly
Returns the value of attribute minion.
-
#scp_connector ⇒ Object
readonly
Returns the value of attribute scp_connector.
-
#ssh_connector ⇒ Object
readonly
Returns the value of attribute ssh_connector.
Instance Method Summary collapse
- #exec(*commands) ⇒ Object
-
#initialize(minion, ssh_connector = Net::SSH, scp_connector = Net::SCP, command_executor = CommandExecution) ⇒ Session
constructor
A new instance of Session.
- #scp(local_path, remote_path) ⇒ Object
- #sudo(*commands) ⇒ Object
Constructor Details
#initialize(minion, ssh_connector = Net::SSH, scp_connector = Net::SCP, command_executor = CommandExecution) ⇒ Session
Returns a new instance of Session.
8 9 10 11 12 13 14 15 16 |
# File 'lib/minionizer/session.rb', line 8 def initialize(minion, ssh_connector=Net::SSH, scp_connector=Net::SCP, command_executor=CommandExecution) @minion = minion @ssh_connector = ssh_connector @scp_connector = scp_connector @command_executor = command_executor end |
Instance Attribute Details
#command_executor ⇒ Object (readonly)
Returns the value of attribute command_executor.
4 5 6 |
# File 'lib/minionizer/session.rb', line 4 def command_executor @command_executor end |
#minion ⇒ Object (readonly)
Returns the value of attribute minion.
4 5 6 |
# File 'lib/minionizer/session.rb', line 4 def minion @minion end |
#scp_connector ⇒ Object (readonly)
Returns the value of attribute scp_connector.
4 5 6 |
# File 'lib/minionizer/session.rb', line 4 def scp_connector @scp_connector end |
#ssh_connector ⇒ Object (readonly)
Returns the value of attribute ssh_connector.
4 5 6 |
# File 'lib/minionizer/session.rb', line 4 def ssh_connector @ssh_connector end |
Instance Method Details
#exec(*commands) ⇒ Object
29 30 31 32 33 |
# File 'lib/minionizer/session.rb', line 29 def exec(*commands) = commands.last.is_a?(Hash) ? commands.pop : {} results = commands.map { |command| execution(command, ).call } results.length == 1 ? results.first : results end |
#scp(local_path, remote_path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/minionizer/session.rb', line 35 def scp(local_path, remote_path) if with_sudo? tmp_filename = "#{SecureRandom.hex}.minionizer_tempfile" scp_connection.upload!(local_path, "#{tmp_filename}") exec("mv #{tmp_filename} #{remote_path}") else scp_connection.upload!(local_path, remote_path) end end |
#sudo(*commands) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/minionizer/session.rb', line 18 def sudo(*commands) @with_sudo = true if commands.any? return exec(*commands) else yield self end ensure @with_sudo = false end |