Class: Handyman::Blueprint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject

Returns the value of attribute config_file.



21
22
23
# File 'lib/handyman.rb', line 21

def config_file
  @config_file
end

#optsObject

Returns the value of attribute opts.



21
22
23
# File 'lib/handyman.rb', line 21

def opts
  @opts
end

#run_listObject

Returns the value of attribute run_list.



21
22
23
# File 'lib/handyman.rb', line 21

def run_list
  @run_list
end

#sshObject

Returns the value of attribute ssh.



21
22
23
# File 'lib/handyman.rb', line 21

def ssh
  @ssh
end

Instance Method Details

#buildObject



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_instructionsObject



39
40
41
# File 'lib/handyman.rb', line 39

def configuration_instructions
  YAML.load interpolated_config
end

#executeObject



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_configObject



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