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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/itamae/runner.rb', line 30 def initialize(backend, ) @backend = backend @options = prepare_handler @node = create_node @tmpdir = [:tmp_dir] || '/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.
23 24 25 |
# File 'lib/itamae/runner.rb', line 23 def backend @backend end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
27 28 29 |
# File 'lib/itamae/runner.rb', line 27 def children @children end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
28 29 30 |
# File 'lib/itamae/runner.rb', line 28 def handler @handler end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
25 26 27 |
# File 'lib/itamae/runner.rb', line 25 def node @node end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/itamae/runner.rb', line 24 def @options end |
#tmpdir ⇒ Object (readonly)
Returns the value of attribute tmpdir.
26 27 28 |
# File 'lib/itamae/runner.rb', line 26 def tmpdir @tmpdir end |
Class Method Details
.run(recipe_files, backend_type, options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/itamae/runner.rb', line 7 def run(recipe_files, backend_type, ) unless recipe_files.is_a? Array raise ArgumentError, 'recipe_files must be an Array' end Itamae.logger.info "Starting Itamae... #{[:dry_run] ? '(dry-run)' : ''}" backend = Backend.create(backend_type, ) runner = self.new(backend, ) runner.load_recipes(recipe_files) runner.run runner end |
Instance Method Details
#diff? ⇒ Boolean
89 90 91 |
# File 'lib/itamae/runner.rb', line 89 def diff? @diff end |
#diff_found! ⇒ Object
93 94 95 |
# File 'lib/itamae/runner.rb', line 93 def diff_found! @diff = true end |
#dry_run? ⇒ Boolean
72 73 74 |
# File 'lib/itamae/runner.rb', line 72 def dry_run? @options[:dry_run] end |
#load_recipes(paths) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/itamae/runner.rb', line 45 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
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/itamae/runner.rb', line 59 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
76 77 78 79 80 81 |
# File 'lib/itamae/runner.rb', line 76 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
83 84 85 86 87 |
# File 'lib/itamae/runner.rb', line 83 def save_profile(path) open(path, 'w', 0600) do |f| f.write(@backend.executed_commands.to_json) end end |