Class: ChefGen::FlavorBase
- Inherits:
-
Object
- Object
- ChefGen::FlavorBase
- Includes:
- CopyHelpers, ResourceHelpers, Hooks
- Defined in:
- lib/chef_gen/flavor_base.rb,
lib/chef_gen/flavor_base/copy_helpers.rb,
lib/chef_gen/flavor_base/resource_helpers.rb
Overview
a base for ChefDK Template Flavors
Defined Under Namespace
Modules: CopyHelpers, ResourceHelpers
Constant Summary collapse
- VERSION =
the version of the gem
'0.9.0'
Instance Attribute Summary collapse
-
#directories ⇒ Array<String>
readonly
a list of directory resources.
-
#files ⇒ Array<String>
readonly
a list of file resources with action :create.
-
#files_if_missing ⇒ Array<String>
readonly
a list of file resources with action :create_if_missing.
-
#snippets ⇒ Array<Class>
readonly
a list of snippet classes to mix in.
-
#templates ⇒ Array<String>
readonly
a list of template resources with action :create.
-
#templates_if_missing ⇒ Array<String>
readonly
a list of template resources with action :create_if_missing.
-
#tocopy ⇒ Array<Array>
readonly
a list of pairs of src/dst files or directories to copy into the temporary directory.
-
#type ⇒ String
readonly
the type of object being generated (cookbook, repo, etc.).
Instance Method Summary collapse
-
#add_content ⇒ void
constructs and calls the #add_content of each snippet, then calls #copy_content to copy the files to the temporary directory.
-
#declare_resources ⇒ void
constructs and calls the #declare_resources method of each snippet, then calls #add_resources to add the resources to the recipe.
-
#generate_mode? ⇒ Boolean
determines if the flavor is in generate mode.
-
#initialize(temp_path: nil, type: nil, recipe: nil) ⇒ FlavorBase
constructor
A new instance of FlavorBase.
-
#setup_mode? ⇒ Boolean
determines if the flavor is in setup mode.
-
#snippet?(name) ⇒ Boolean
a predicate to determine if a snippet has been included in a flavor.
Methods included from ResourceHelpers
#add_directories, #add_files, #add_templates
Constructor Details
#initialize(temp_path) ⇒ self #initialize(type, recipe) ⇒ self
Returns a new instance of FlavorBase.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef_gen/flavor_base.rb', line 79 def initialize(temp_path: nil, type: nil, recipe: nil) # run before hook run_hook :before_initialize # set up instance variables @recipe = recipe # start with an empty list of snippets @snippets = [] @enabled_snippets = {} if setup_mode? @temp_path = temp_path # in setup mode, start with an empty list of things to copy @tocopy = [] else @type = type # in generate mode, start empty dir, file and template lists @directories = [] @files = [] @files_if_missing = [] @templates = [] @templates_if_missing = [] end # run after hook run_hook :after_initialize end |
Instance Attribute Details
#directories ⇒ Array<String> (readonly)
a list of directory resources
49 50 51 |
# File 'lib/chef_gen/flavor_base.rb', line 49 def directories @directories end |
#files ⇒ Array<String> (readonly)
a list of file resources with action :create
53 54 55 |
# File 'lib/chef_gen/flavor_base.rb', line 53 def files @files end |
#files_if_missing ⇒ Array<String> (readonly)
a list of file resources with action :create_if_missing
57 58 59 |
# File 'lib/chef_gen/flavor_base.rb', line 57 def files_if_missing @files_if_missing end |
#snippets ⇒ Array<Class> (readonly)
a list of snippet classes to mix in
40 41 42 |
# File 'lib/chef_gen/flavor_base.rb', line 40 def snippets @snippets end |
#templates ⇒ Array<String> (readonly)
a list of template resources with action :create
61 62 63 |
# File 'lib/chef_gen/flavor_base.rb', line 61 def templates @templates end |
#templates_if_missing ⇒ Array<String> (readonly)
a list of template resources with action :create_if_missing
65 66 67 |
# File 'lib/chef_gen/flavor_base.rb', line 65 def templates_if_missing @templates_if_missing end |
#tocopy ⇒ Array<Array> (readonly)
a list of pairs of src/dst files or directories to copy into the temporary directory.
45 46 47 |
# File 'lib/chef_gen/flavor_base.rb', line 45 def tocopy @tocopy end |
#type ⇒ String (readonly)
the type of object being generated (cookbook, repo, etc.)
36 37 38 |
# File 'lib/chef_gen/flavor_base.rb', line 36 def type @type end |
Instance Method Details
#add_content ⇒ void
This method returns an undefined value.
constructs and calls the #add_content of each snippet, then calls #copy_content to copy the files to the temporary directory
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/chef_gen/flavor_base.rb', line 125 def add_content # construct each snippet in setup mode run_hook :before_snippet_construct snippets.map! { |s| s.new(flavor: self) } mark_enabled_snippets run_hook :after_snippet_construct # call hooks to add content run_hook :before_add_content run_hook :do_add_content run_hook :after_add_content # copy queued content run_hook :before_copy_content copy_content run_hook :after_copy_content end |
#declare_resources ⇒ void
This method returns an undefined value.
constructs and calls the #declare_resources method of each snippet, then calls #add_resources to add the resources to the recipe
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/chef_gen/flavor_base.rb', line 146 def declare_resources # declare the target directory @recipe.send(:directory, destination_path('.')) # construct each snippet in generate mode run_hook :before_snippet_construct snippets.map! { |s| s.new(flavor: self, recipe: @recipe) } mark_enabled_snippets run_hook :after_snippet_construct # call hooks to add content run_hook :before_declare_resources run_hook :do_declare_resources run_hook :after_declare_resources # add queued resources to the recipe run_hook :before_add_resources add_resources run_hook :after_add_resources end |
#generate_mode? ⇒ Boolean
determines if the flavor is in generate mode
118 119 120 |
# File 'lib/chef_gen/flavor_base.rb', line 118 def generate_mode? !setup_mode? end |
#setup_mode? ⇒ Boolean
determines if the flavor is in setup mode
111 112 113 |
# File 'lib/chef_gen/flavor_base.rb', line 111 def setup_mode? @recipe.nil? end |
#snippet?(name) ⇒ Boolean
a predicate to determine if a snippet has been included in a flavor
170 171 172 |
# File 'lib/chef_gen/flavor_base.rb', line 170 def snippet?(name) @enabled_snippets.key?(name) end |