Class: Itamae::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, options) ⇒ Runner

Returns a new instance of Runner.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/itamae/runner.rb', line 32

def initialize(backend, options)
  @backend = backend
  @options = options

  @node = create_node
  @tmpdir = "/tmp/itamae_tmp"
  @children = RecipeChildren.new

  @backend.run_command(["mkdir", "-p", @tmpdir])
  @backend.run_command(["chmod", "777", @tmpdir])
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



27
28
29
# File 'lib/itamae/runner.rb', line 27

def backend
  @backend
end

#childrenObject (readonly)

Returns the value of attribute children.



30
31
32
# File 'lib/itamae/runner.rb', line 30

def children
  @children
end

#nodeObject (readonly)

Returns the value of attribute node.



28
29
30
# File 'lib/itamae/runner.rb', line 28

def node
  @node
end

#tmpdirObject (readonly)

Returns the value of attribute tmpdir.



29
30
31
# File 'lib/itamae/runner.rb', line 29

def tmpdir
  @tmpdir
end

Class Method Details

.run(recipe_files, backend_type, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/itamae/runner.rb', line 8

def run(recipe_files, backend_type, options)
  Logger.info "Starting Itamae..."

  backend = Backend.create(backend_type, options)
  runner = self.new(backend, options)
  runner.load_recipes(recipe_files)

  if dot_file = options[:dot]
    Logger.info "Writing dependency graph in DOT to #{dot_file}..."
    open(dot_file, 'w') do |f|
      f.write(runner.children.deps_in_dot)
    end
    return
  end

  runner.run(dry_run: options[:dry_run])
end

Instance Method Details

#load_recipes(paths) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/itamae/runner.rb', line 44

def load_recipes(paths)
  paths.each do |path|
    recipe = Recipe.new(self, File.expand_path(path))
    children << recipe
    recipe.load
  end
end

#run(options) ⇒ Object



52
53
54
55
# File 'lib/itamae/runner.rb', line 52

def run(options)
  children.run(options)
  @backend.finalize
end