Class: Consist::Consistfile

Inherits:
Object
  • Object
show all
Includes:
SSHKit::DSL
Defined in:
lib/consist/consistfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(server_ip, specified_step:, consistfile:) ⇒ Consistfile

Returns a new instance of Consistfile.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/consist/consistfile.rb', line 14

def initialize(server_ip, specified_step:, consistfile:)
  @server_ip = server_ip
  @specified_step = specified_step
  consistfile_path = if consistfile
    File.expand_path(consistfile, Dir.pwd)
  else
    File.expand_path("Consistfile", Dir.pwd)
  end

  consistfile_contents = File.read(consistfile_path)
  instance_eval(consistfile_contents)
end

Instance Method Details

#config(id, val) ⇒ Object



57
58
59
# File 'lib/consist/consistfile.rb', line 57

def config(id, val)
  Consist.config[id] = val
end

#consist(&definition) ⇒ Object



27
28
29
# File 'lib/consist/consistfile.rb', line 27

def consist(&definition)
  instance_eval(&definition)
end

#file(id, &definition) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/consist/consistfile.rb', line 49

def file(id, &definition)
  return unless definition

  contents = yield

  Consist.files << {id:, contents:}
end

#recipe(id, &definition) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/consist/consistfile.rb', line 31

def recipe(id, &definition)
  recipe = Consist::Recipe.new(id, &definition)

  puts "Executing Recipe: #{recipe.name}"

  if @specified_step.nil?
    recipe.steps.each { exec_step(_1) }
  else
    puts "Specific step targeted: #{@specified_step.to_sym}"
    specified_step, *_rest = recipe.steps.select { _1.id === @specified_step.to_sym }
    raise "Step with id #{@specified_step.to_sym} not found." unless specified_step

    exec_step(specified_step)
  end

  puts "Execution of #{recipe.name} has completed."
end