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

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

Parameters:

  • directories (Array<String>)

    the directories to create



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.

Parameters:

  • files (Array<String>)

    list of files relative to target root. If content is provided, this should only contain one file

  • resource_action (Symbol) (defaults to: :create_if_missing)

    the action to send to the resource

  • type (Symbol) (defaults to: :cookbook_file)

    the type of resource, :file or :cookbook_file

  • attrs (Hash) (defaults to: {})

    additional attributes to pass to the 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

Parameters:

  • templates (Array<String>)

    list of templates relative to target root

  • resource_action (Symbol) (defaults to: :create_if_missing)

    the action to send to the resource

  • attrs (Hash) (defaults to: {})

    additional attributes to pass to the resource



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