Class: Itamae::Runner
- Inherits:
-
Object
- Object
- Itamae::Runner
- Defined in:
- lib/itamae/runner.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tmpdir ⇒ Object
readonly
Returns the value of attribute tmpdir.
Class Method Summary collapse
Instance Method Summary collapse
- #diff? ⇒ Boolean
- #diff_found! ⇒ Object
- #dry_run? ⇒ Boolean
-
#initialize(backend, options) ⇒ Runner
constructor
A new instance of Runner.
- #load_recipes(paths) ⇒ Object
- #run ⇒ Object
- #save_dependency_graph(path) ⇒ Object
- #save_profile(path) ⇒ Object
Constructor Details
#initialize(backend, options) ⇒ Runner
Returns a new instance of Runner.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/itamae/runner.rb', line 27 def initialize(backend, ) @backend = backend @options = prepare_handler @node = create_node @tmpdir = "/tmp/itamae_tmp" @children = RecipeChildren.new @diff = false @backend.run_command(["mkdir", "-p", @tmpdir]) @backend.run_command(["chmod", "777", @tmpdir]) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
20 21 22 |
# File 'lib/itamae/runner.rb', line 20 def backend @backend end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
24 25 26 |
# File 'lib/itamae/runner.rb', line 24 def children @children end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
25 26 27 |
# File 'lib/itamae/runner.rb', line 25 def handler @handler end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
22 23 24 |
# File 'lib/itamae/runner.rb', line 22 def node @node end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/itamae/runner.rb', line 21 def @options end |
#tmpdir ⇒ Object (readonly)
Returns the value of attribute tmpdir.
23 24 25 |
# File 'lib/itamae/runner.rb', line 23 def tmpdir @tmpdir end |
Class Method Details
.run(recipe_files, backend_type, options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/itamae/runner.rb', line 8 def run(recipe_files, backend_type, ) Itamae.logger.info "Starting Itamae..." backend = Backend.create(backend_type, ) runner = self.new(backend, ) runner.load_recipes(recipe_files) runner.run runner end |
Instance Method Details
#diff? ⇒ Boolean
86 87 88 |
# File 'lib/itamae/runner.rb', line 86 def diff? @diff end |
#diff_found! ⇒ Object
90 91 92 |
# File 'lib/itamae/runner.rb', line 90 def diff_found! @diff = true end |
#dry_run? ⇒ Boolean
69 70 71 |
# File 'lib/itamae/runner.rb', line 69 def dry_run? @options[:dry_run] end |
#load_recipes(paths) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/itamae/runner.rb', line 42 def load_recipes(paths) paths.each do |path| = File.(path) if path.include?('::') gem_path = Recipe.find_recipe_in_gem(path) = gem_path if gem_path end recipe = Recipe.new(self, ) children << recipe recipe.load end end |
#run ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/itamae/runner.rb', line 56 def run if recipe_graph_file = [:recipe_graph] save_dependency_graph(recipe_graph_file) end children.run @backend.finalize if profile = [:profile] save_profile(profile) end end |
#save_dependency_graph(path) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/itamae/runner.rb', line 73 def save_dependency_graph(path) Itamae.logger.info "Writing recipe dependency graph to #{path}..." open(path, 'w') do |f| f.write(children.dependency_in_dot) end end |
#save_profile(path) ⇒ Object
80 81 82 83 84 |
# File 'lib/itamae/runner.rb', line 80 def save_profile(path) open(path, 'w', 0600) do |f| f.write(@backend.executed_commands.to_json) end end |