Module: ChefGen::FlavorBase::ResourceHelpers
- Included in:
- ChefGen::FlavorBase, Snippet::GitInit
- Defined in:
- lib/chef_gen/flavor_base/resource_helpers.rb
Overview
helpers to add resources to recipes; used in the generate phase
Instance Method Summary collapse
-
#add_directories(directories) ⇒ void
private
adds directories to the recipes.
-
#add_files(files, resource_action = :create_if_missing, type = :cookbook_file, attrs = {}) ⇒ void
private
adds files to the recipes.
-
#add_templates(templates, resource_action = :create_if_missing, attrs = {}) ⇒ void
private
adds templates to the recipes.
Instance Method Details
#add_directories(directories) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
adds directories to the recipes
10 11 12 13 14 15 16 17 |
# File 'lib/chef_gen/flavor_base/resource_helpers.rb', line 10 def add_directories(directories) run_hook :before_add_directories, directories directories.each do |dir| dst = destination_path(dir) @recipe.send(:directory, dst) end run_hook :after_add_directories, directories end |
#add_files(files, resource_action = :create_if_missing, type = :cookbook_file, attrs = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
adds files to the recipes. Without content, creates a cookbook_file resource, otherwise creates a file resource.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chef_gen/flavor_base/resource_helpers.rb', line 28 def add_files(files, resource_action = :create_if_missing, type = :cookbook_file, attrs = {}) run_hook :before_add_files, files, resource_action, type, attrs files.each do |file| src = source_path(file) # :nocov: @recipe.send(type, destination_path(file)) do action resource_action source src if :cookbook_file == type attrs.each { |a, v| send a, v } end # :nocov: end run_hook :after_add_files, files, resource_action, type, attrs end |
#add_templates(templates, resource_action = :create_if_missing, attrs = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
adds templates to the recipes
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/chef_gen/flavor_base/resource_helpers.rb', line 49 def add_templates(templates, resource_action = :create_if_missing, attrs = {}) run_hook :before_add_templates, templates, resource_action, attrs templates.each do |template| src = "#{source_path(template)}.erb" # :nocov: @recipe.send(:template, destination_path(template)) do source src action resource_action helpers ChefDK::Generator::TemplateHelper attrs.each { |a, v| send a, v } end # :nocov: run_hook :after_add_templates, templates, resource_action, attrs end end |