Class: Handyman::Blueprint
- Inherits:
-
Object
- Object
- Handyman::Blueprint
- Defined in:
- lib/handyman.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#run_list ⇒ Object
Returns the value of attribute run_list.
-
#ssh ⇒ Object
Returns the value of attribute ssh.
Instance Method Summary collapse
- #build ⇒ Object
- #configuration_instructions ⇒ Object
- #execute ⇒ Object
-
#initialize(host, user, password) ⇒ Blueprint
constructor
A new instance of Blueprint.
- #interpolated_config ⇒ Object
Constructor Details
#initialize(host, user, password) ⇒ Blueprint
Returns a new instance of Blueprint.
23 24 25 26 27 28 29 30 31 |
# File 'lib/handyman.rb', line 23 def initialize(host, user, password) @ssh = Net::SSH.start(host, user, password: password) @run_list = [] @config_file = 'lib/config.yml' @opts = { email: '[email protected]', name: 'John Doe' } end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
21 22 23 |
# File 'lib/handyman.rb', line 21 def config_file @config_file end |
#opts ⇒ Object
Returns the value of attribute opts.
21 22 23 |
# File 'lib/handyman.rb', line 21 def opts @opts end |
#run_list ⇒ Object
Returns the value of attribute run_list.
21 22 23 |
# File 'lib/handyman.rb', line 21 def run_list @run_list end |
#ssh ⇒ Object
Returns the value of attribute ssh.
21 22 23 |
# File 'lib/handyman.rb', line 21 def ssh @ssh end |
Instance Method Details
#build ⇒ Object
33 34 35 36 37 |
# File 'lib/handyman.rb', line 33 def build configuration_instructions.each do |instruction| @run_list << { instruction[0] => instruction[1] } end end |
#configuration_instructions ⇒ Object
39 40 41 |
# File 'lib/handyman.rb', line 39 def configuration_instructions YAML.load interpolated_config end |
#execute ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/handyman.rb', line 49 def execute @run_list.each do |instruction| instruction.each_pair do |title, commands| puts title commands.to_a.each{ |command| ssh.exec! command } end end end |
#interpolated_config ⇒ Object
43 44 45 46 47 |
# File 'lib/handyman.rb', line 43 def interpolated_config File.open(@config_file,'r').each_line.reduce(''){ |str, line| str << line % opts } end |