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:, consist_dir:, consistfile:) ⇒ Consistfile

Returns a new instance of Consistfile.



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

def initialize(server_ip, specified_step:, consist_dir:, consistfile:)
  @server_ip = server_ip
  @specified_step = specified_step
  Consist.consist_dir = consist_dir || ".consist"

  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



62
63
64
# File 'lib/consist/consistfile.rb', line 62

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

#consist(&definition) ⇒ Object



30
31
32
# File 'lib/consist/consistfile.rb', line 30

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

#file(id, &definition) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/consist/consistfile.rb', line 51

def file(id, &definition)
  if definition
    contents = yield
  else
    file_contents = Consist::Resolver.new(pwd: Dir.pwd).resolve_artifact(type: :file, id:)
    contents = file_contents
  end

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

#recipe(id, &definition) ⇒ Object



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

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