Class: Koch::Runner

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

Overview

This class evaluates the Rezeptfile and applies the resources

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rezeptfile) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
14
15
16
17
18
19
# File 'lib/koch.rb', line 10

def initialize(rezeptfile)
  @rezeptfile = rezeptfile

  @packages = Packages.new
  @snap_packages = SnapPackages.new

  @resources = Resources.new

  @delete = false
end

Class Method Details

.make_method_body(add, delete = nil, collection = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/koch.rb', line 41

def self.make_method_body(add, delete = nil, collection = nil)
  proc do |name, &block|
    r = if @delete
          fatal "Delete not supported for resource #{name}" if delete.nil?

          delete.new(name)
        else
          add.new(name)
        end

    # block_given? does not work.
    r.instance_eval(&block) if block

    if collection.nil?
      @resources << r
    else
      c = instance_variable_get(collection)
      c << r
    end
  end
end

Instance Method Details

#goObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/koch.rb', line 21

def go
  info("Starting Koch runner (version #{VERSION}).")
  info("DRY RUN MODE! Add --no-dry-run to apply changes.") if @@dry_run

  eval_rezeptfile
  apply!

  @resources.reloads.each do |r|
    maybe "systemctl reload #{r}"
  end
  @resources.restarts.each do |r|
    maybe "systemctl restart #{r}"
  end
  @resources.on_changes.each do |r|
    maybe r
  end

  info("Run complete.")
end