chef-gen-flavors 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +5 -0
  3. data/LICENSE +2 -0
  4. data/Manifest.txt +0 -37
  5. data/README.md +113 -330
  6. data/chef-gen-flavors.gemspec +9 -9
  7. data/lib/chef_gen/flavors.rb +34 -100
  8. metadata +16 -47
  9. data/lib/chef_gen/flavor_base.rb +0 -266
  10. data/lib/chef_gen/snippet/attributes.rb +0 -35
  11. data/lib/chef_gen/snippet/chef_spec.rb +0 -111
  12. data/lib/chef_gen/snippet/cookbook_base.rb +0 -160
  13. data/lib/chef_gen/snippet/example_file.rb +0 -38
  14. data/lib/chef_gen/snippet/example_template.rb +0 -40
  15. data/lib/chef_gen/snippet/git_init.rb +0 -21
  16. data/lib/chef_gen/snippet/recipes.rb +0 -37
  17. data/lib/chef_gen/snippet/resource_provider.rb +0 -42
  18. data/lib/chef_gen/snippet/standard_ignore.rb +0 -73
  19. data/lib/chef_gen/snippet/style_foodcritic.rb +0 -51
  20. data/lib/chef_gen/snippet/style_rubocop.rb +0 -94
  21. data/lib/chef_gen/snippet/style_tailor.rb +0 -48
  22. data/lib/chef_gen/snippet/test_kitchen.rb +0 -109
  23. data/lib/chef_gen/snippets.rb +0 -18
  24. data/shared/snippet/attributes/attributes_default_rb.erb +0 -8
  25. data/shared/snippet/chef_spec/_rspec.erb +0 -2
  26. data/shared/snippet/chef_spec/spec_chef_runner_context_rb.erb +0 -36
  27. data/shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb +0 -7
  28. data/shared/snippet/chef_spec/spec_spec_helper_rb.erb +0 -95
  29. data/shared/snippet/cookbookbase/Berksfile.erb +0 -12
  30. data/shared/snippet/cookbookbase/CHANGELOG_md.erb +0 -5
  31. data/shared/snippet/cookbookbase/Gemfile.erb +0 -18
  32. data/shared/snippet/cookbookbase/Guardfile.erb +0 -16
  33. data/shared/snippet/cookbookbase/README_md.erb +0 -92
  34. data/shared/snippet/cookbookbase/Rakefile.erb +0 -20
  35. data/shared/snippet/cookbookbase/metadata_rb.erb +0 -10
  36. data/shared/snippet/examplefile/files_default_example_conf +0 -34
  37. data/shared/snippet/exampletemplate/templates_default_example_conf_erb +0 -22
  38. data/shared/snippet/recipes/recipes_default_rb.erb +0 -9
  39. data/shared/snippet/resourceprovider/providers_default_rb.erb +0 -20
  40. data/shared/snippet/resourceprovider/resources_default_rb.erb +0 -9
  41. data/shared/snippet/stylerubocop/_rubocop_yml.erb +0 -31
  42. data/shared/snippet/testkitchen/_kitchen_yml.erb +0 -30
  43. data/shared/snippet/testkitchen/libraries_kitchen_helper_rb +0 -13
  44. data/shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb +0 -16
  45. data/shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0b26e3895493d90b9d965e5d2d208372df82043
4
- data.tar.gz: 7091c3ba4bf917a179fd67bba47723da1422544a
3
+ metadata.gz: 4b0953fd114c2f2abb72a230b6a78bf0e020000a
4
+ data.tar.gz: 771448a5c60f983e57ceace57260c6e0944cdd5d
5
5
  SHA512:
6
- metadata.gz: f0199d065dcf48a1e398f6624250f79af8fb0af4ebd1f6bd9b80b03952eacf77829f938ffa5b6e6f4ea0ffa9e40905ce9bd7f73273fe436ab61739b924257e38
7
- data.tar.gz: 710bf0afa1023a3ac92c2ca47058d6cae9e114201f7485ac06f22724bcdbc7f53408186b64170772eade67272ae620304c2041aac5934362cbe8685ec26e527d
6
+ metadata.gz: af181b0de509ad3c4e1925f1cb11eee12cc55844a5178a3d0253d9e351c2453cad52494aec943efbc174434fa4c3e0e346bd2919d2789d30a8553cb159779741
7
+ data.tar.gz: 0968b5d2044d14bb0fcf6185a66fcc2f29bc709f49c70c224d3c7bd8fb563ea71d3db95af85a72e52478b8995d09c647a3c9ad1d8ac3a3493d6e3dd55ae247a2
data/History.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog for chef-gen-flavors
2
2
 
3
+ ## 0.9.0
4
+
5
+ * removed ChefGen::FlavorBase (and the snippets it uses) from this distribution and moved into a separate gem: [chef-gen-flavor-base](https://github.com/jf647/chef-gen-flavor-base)
6
+ * the new flavor base has breaking API changes (details below); flavor authors should refer to the documentation in the new distribution for details
7
+
3
8
  ## 0.8.6
4
9
 
5
10
  This version contains no code changes; this is a courtesy version bump
data/LICENSE CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Copyright 2015 Nordstrom, Inc.
4
4
 
5
+ Copyright 2015 James FitzGibbon
6
+
5
7
  Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
8
  use this file except in compliance with the License. You may obtain a copy
7
9
  of the License at
@@ -5,7 +5,6 @@ Manifest.txt
5
5
  README.md
6
6
  chef-gen-flavors.gemspec
7
7
  lib/chef_gen/flavor.rb
8
- lib/chef_gen/flavor_base.rb
9
8
  lib/chef_gen/flavors.rb
10
9
  lib/chef_gen/flavors/cucumber.rb
11
10
  lib/chef_gen/flavors/cucumber/bundle.rb
@@ -14,39 +13,3 @@ lib/chef_gen/flavors/cucumber/kitchen.rb
14
13
  lib/chef_gen/flavors/cucumber/knife.rb
15
14
  lib/chef_gen/flavors/cucumber/rake.rb
16
15
  lib/chef_gen/flavors/cucumber/regex.rb
17
- lib/chef_gen/snippet/attributes.rb
18
- lib/chef_gen/snippet/chef_spec.rb
19
- lib/chef_gen/snippet/cookbook_base.rb
20
- lib/chef_gen/snippet/example_file.rb
21
- lib/chef_gen/snippet/example_template.rb
22
- lib/chef_gen/snippet/git_init.rb
23
- lib/chef_gen/snippet/recipes.rb
24
- lib/chef_gen/snippet/resource_provider.rb
25
- lib/chef_gen/snippet/standard_ignore.rb
26
- lib/chef_gen/snippet/style_foodcritic.rb
27
- lib/chef_gen/snippet/style_rubocop.rb
28
- lib/chef_gen/snippet/style_tailor.rb
29
- lib/chef_gen/snippet/test_kitchen.rb
30
- lib/chef_gen/snippets.rb
31
- shared/snippet/attributes/attributes_default_rb.erb
32
- shared/snippet/chef_spec/_rspec.erb
33
- shared/snippet/chef_spec/spec_chef_runner_context_rb.erb
34
- shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb
35
- shared/snippet/chef_spec/spec_spec_helper_rb.erb
36
- shared/snippet/cookbookbase/Berksfile.erb
37
- shared/snippet/cookbookbase/CHANGELOG_md.erb
38
- shared/snippet/cookbookbase/Gemfile.erb
39
- shared/snippet/cookbookbase/Guardfile.erb
40
- shared/snippet/cookbookbase/README_md.erb
41
- shared/snippet/cookbookbase/Rakefile.erb
42
- shared/snippet/cookbookbase/metadata_rb.erb
43
- shared/snippet/examplefile/files_default_example_conf
44
- shared/snippet/exampletemplate/templates_default_example_conf_erb
45
- shared/snippet/recipes/recipes_default_rb.erb
46
- shared/snippet/resourceprovider/providers_default_rb.erb
47
- shared/snippet/resourceprovider/resources_default_rb.erb
48
- shared/snippet/stylerubocop/_rubocop_yml.erb
49
- shared/snippet/testkitchen/_kitchen_yml.erb
50
- shared/snippet/testkitchen/libraries_kitchen_helper_rb
51
- shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb
52
- shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb
data/README.md CHANGED
@@ -1,16 +1,11 @@
1
1
  # chef-gen-flavors
2
2
 
3
- * home :: https://github.com/Nordstrom/chef-gen-flavors
3
+ * home :: https://github.com/jf647/chef-gen-flavors
4
4
  * license :: [Apache2](http://www.apache.org/licenses/LICENSE-2.0)
5
5
  * gem version :: [![Gem Version](https://badge.fury.io/rb/chef-gen-flavors.png)](http://badge.fury.io/rb/chef-gen-flavors)
6
- * build status :: [![Circle CI](https://circleci.com/gh/Nordstrom/chef-gen-flavors.svg?style=svg)](https://circleci.com/gh/Nordstrom/chef-gen-flavors)
7
- * code climate :: [![Code Climate](https://codeclimate.com/github/Nordstrom/chef-gen-flavors/badges/gpa.svg)](https://codeclimate.com/github/Nordstrom/chef-gen-flavors)
8
- * docs :: [![Inline docs](http://inch-ci.org/github/nordstrom/chef-gen-flavors.svg?branch=master)](http://inch-ci.org/github/nordstrom/chef-gen-flavors)
9
-
10
- ## UPCOMING API CHANGES
11
-
12
- Please see the [changelog](History.md) for details of upcoming breaking API changes in
13
- the 0.9.x series.
6
+ * build status :: [![Circle CI](https://circleci.com/gh/jf647/chef-gen-flavors.svg?style=svg)](https://circleci.com/gh/jf647/chef-gen-flavors)
7
+ * code climate :: [![Code Climate](https://codeclimate.com/github/jf647/chef-gen-flavors/badges/gpa.svg)](https://codeclimate.com/github/jf647/chef-gen-flavors)
8
+ * docs :: [![Inline docs](http://inch-ci.org/github/jf647/chef-gen-flavors.svg?branch=master)](http://inch-ci.org/github/jf647/chef-gen-flavors)
14
9
 
15
10
  ## DESCRIPTION
16
11
 
@@ -21,19 +16,52 @@ This gem simply provides a framework; templates are provided by separate
21
16
  gems, which you can host privately for use within your organization or
22
17
  publicly for the Chef community to use.
23
18
 
24
- At present this is focused primarily on providing templates for generation of
25
- cookbooks, as this is where most organization-specific customization takes place.
26
- Support for the other artifacts that ChefDK can generate may work, but is not
27
- the focus of early releases.
19
+ [chef-gen-flavor-base](https://github.com/jf647/chef-gen-flavor-base) is
20
+ a base class that makes it easy to compose a flavor from reusable
21
+ snippets of functionality, and using it is highly recommended. Using
22
+ chef-gen-flavors on its own is only suitable if you already have a
23
+ template which is a copy of the skeleton provided by ChefDK.
24
+
25
+ At present this is focused primarily on providing templates for
26
+ generation of cookbooks, as this is where most organization-specific
27
+ customization takes place. Support for the other artifacts that ChefDK
28
+ can generate may work, but is not the focus of early releases.
29
+
30
+ ### BREAKING API CHANGES
31
+
32
+ v0.9.0 of chef-gen-flavors is very different from chef-gen-flavors
33
+ v0.8.x. Flavors will need to be re-worked, and the base flavor class
34
+ and associated snippets have been extracted to their own gem.
35
+
36
+ v0.8.6 contained a warning about this change; if you are not ready to
37
+ upgrade your flavor you can pin to this version to keep the old API.
28
38
 
29
39
  ## INSTALLATION
30
40
 
31
- chef gem install chef-gen-flavors
41
+ You should not install this gem directly; it will be installed as a
42
+ dependency of a flavor gem. If you are developing a flavor, declare
43
+ this gem a dependency of your gem in your gemspec file:
32
44
 
33
- You will also need to install at least one plugin, which may be distributed
34
- via Rubygems (in which case you install using `chef gem`) or as source, in
35
- which case you should refer to the installation documentation that comes with
36
- the plugin.
45
+ ```ruby
46
+ Gem::Specification.new do |s|
47
+ s.name = 'chef-gen-flavor-awesome'
48
+ s.add_runtime_dependency('chef-gen-flavors', ['~> 0.9'])
49
+ ...
50
+ end
51
+ ```
52
+
53
+ Then make bundler read your gemspec:
54
+
55
+ ```ruby
56
+ source 'https://rubygems.org/'
57
+ gemspec
58
+ ```
59
+
60
+ And use bundler to install your dependencies:
61
+
62
+ ```bash
63
+ $ bundle
64
+ ```
37
65
 
38
66
  ## PREREQUISITES
39
67
 
@@ -68,13 +96,6 @@ By default, this gem does not offer the built-in ChefDK template as an
68
96
  option. By setting the environment variable CHEFDK_FLAVOR, the
69
97
  option `builtin` will be offered.
70
98
 
71
- ## TERMINOLOGY
72
-
73
- (because everything in the Chef ecosystem has to have foodie names)
74
-
75
- * Flavor - a type of template. Provided by a plugin in the namespace `ChefGen::Flavor::`. Flavors can be distributed as ruby gems inside or outside of your organization.
76
- * Snippet - a small piece of a code_generator cookbook that flavors can compose together to avoid repeating themselves. Nominally provided by a module in the namespace `ChefGen::Snippet::`, but can be defined in any module. chef-gen-flavors comes with several common snippets, but you can create your own and package them as standalone gems or as part of a flavor gem
77
-
78
99
  ## FLAVORS
79
100
 
80
101
  This gem uses [little-plugger](https://rubygems.org/gems/little-plugger) to
@@ -86,16 +107,17 @@ The plugin must define a class inside the naming hierarchy
86
107
  `ChefGen::Flavor::`. The class name should be the filename converted to
87
108
  CamelCase (e.g. `foo_bar.rb` = `FooBar`)
88
109
 
89
- The name of the module must not be in all caps, as little-plugger ignores
110
+ The name of the class must not be in all caps, as little-plugger ignores
90
111
  these (assuming that they are constants).
91
112
 
92
- Plugins must also define a class method named `description`, which is used
93
- both to find the path to the file that defines the plugin and in the prompt
94
- displayed when more than one plugin is available.
95
-
96
113
  You do not have to `require` your plugin; little-plugger searches all
97
114
  installed gems for files matching the globspec.
98
115
 
116
+ Flavor classes must also:
117
+
118
+ * define a NAME constant which is the name of the flavor in lowercase
119
+ * provide an `#add_content` method, which is responsible for copying content to the temporary directory created by chef-gen-flavors
120
+
99
121
  ## EXAMPLE FLAVOR STRUCTURE
100
122
 
101
123
  This example defines a flavor named `Example`. It can only generate
@@ -107,278 +129,60 @@ A functional copy of this plugin is available on rubygems as
107
129
  The directory structure of a plugin looks like this:
108
130
 
109
131
  chef-gen-flavor-example
110
- ├── code_generator
111
- │   ├── files
112
-    │   └── default
113
-    ├── metadata.rb
114
- │   ├── recipes
115
- │   │   └── cookbook.rb
116
- │   └── templates
117
- │   └── default
118
- └── lib
119
- └── chef_gen
120
- └── flavor
121
- └── example.rb
122
-
123
- It is important that the name of the directory in which your generator
124
- cookbook lives matches the name in metadata.rb. ChefDK uses the last
125
- element of the path as the cookbook name, so if you put your cookbook
126
- in a folder called 'cookbook' but your metadata.rb declares the name
127
- as 'code_generator', ChefDK won't be able to find your recipe.
128
-
129
- ## ALTERNATE code_generator PATHS
130
-
131
- By default, the code_generator cookbook is assumed to live in a directory
132
- named `code_generator` four levels higher than the path of the file
133
- definining the plugin.
134
-
135
- To specify that the code_generator cookbook lives elsewhere, define a class
136
- method named `code_generator_path` which takes one argument (the path to the
137
- plugin class) and returns the path to the code_generator cookbook. If the
138
- `Example` plugin wanted to place the code_generator cookbook in a directory
139
- named `template` instead of `code_generator`, it would define an instance
140
- method like this:
141
-
142
- module ChefGen
143
- module Flavor
144
- class Example
145
- class << self
146
- def description
147
- 'example cookbook template'
148
- end
149
-
150
- def code_generator_path(classfile)
151
- File.expand_path(
152
- File.join(
153
- classfile,
154
- '..', '..', '..', '..',
155
- 'template'
156
- )
157
- )
158
- end
159
- end
160
- end
161
- end
162
- end
163
-
164
- For compatibility with all platforms supported by ChefDK, plugins should use
165
- the methods in the `File` class to construct relative paths rather than
166
- assuming what the path separator should be.
167
-
168
- ## GENERATOR PATH COPY
169
-
170
- When #path is called, chef-gen-flavors makes a copy of the selected
171
- generator cookbook to a temporary path, which is what gets returned
172
- and used by ChefDK. This path is cleaned up at exit unless the environment
173
- variable CHEFGEN_NOCLEANTMP is set.
174
-
175
- ## ADDING CONTENT TO THE GENERATOR COPY
176
-
177
- After the generator is copied to a temporary path, the #add_content
178
- instance method is called (if it exists) on the flavor class. It is
179
- passed one arg: the path to the temporary copy.
180
-
181
- This allows flavors to create content dynamically by writing files
182
- to the proper directly. It is exploited by the flavor base class
183
- described below.
184
-
185
- ## FLAVOR BASE CLASS
186
-
187
- Inside of your plugin's code_generator cookbook, you can do anything that
188
- chef-solo can do. If you aren't familiar with the mechanics of the default
189
- generators that comes with chef-dk, you should study [those
190
- recipes](https://github.com/chef/chef-dk/tree/0.5.1/lib/chef-dk/skeletons/code_generator)
191
- first before attempting to create your own.
192
-
193
- To make the job of authoring a custom template easier, this gem comes with a
194
- base class that plugins can inherit from. This provides some useful
195
- features:
196
-
197
- * helpers to create directories and render files and templates using simple name translation
198
- * the ability to create and use snippets that set up commonly used functionality (i.e. ChefSpec or Test Kitchen)
199
- * the ability to prevent files from being overwritten when a template is being applied overtop an existing cookbook
200
-
201
- To use the base class, make it a dependency of your gem and inherit from it:
202
-
203
- require 'chef_gen/flavor_base'
204
-
205
- module ChefGen
206
- module Flavor
207
- class Amazing < FlavorBase
208
- end
132
+ ├── lib
133
+ │   └── chef_gen
134
+    └── flavor
135
+    └── example.rb
136
+ └── shared
137
+ └── flavor
138
+ └── example
139
+ ├── metadata.rb
140
+ └── recipes
141
+ └── cookbook.rb
142
+
143
+ It is important that the name of the flavor matches the name in
144
+ metadata.rb. ChefDK uses the last element of the path as the cookbook
145
+ name, so if you put your cookbook in a folder called 'cookbook' but your
146
+ metadata.rb declares the name as 'example', ChefDK won't be able
147
+ to find your recipe.
148
+
149
+ ## COPYING CONTENT
150
+
151
+ When #path is called, chef-gen-flavors creates a temporary directory,
152
+ which is passes as an argument to the flavor class' constructor:
153
+
154
+ ```ruby
155
+ class ChefGen
156
+ module Flavor
157
+ class Awesome
158
+ NAME = 'awesome'
159
+
160
+ def initialize(temp_path:)
161
+ @temp_path = temp_path
209
162
  end
210
163
  end
211
-
212
- Then in one of your generator recipes like `recipes/cookbook.rb`, create
213
- an instance of your plugin, passing the recipe into which resources will
214
- be injected:
215
-
216
- template = ChefGen::Flavor::Amazing.new(self)
217
-
218
- The plugin has several helper methods you can use:
219
-
220
- * `target_path` returns the full path to the target directory
221
- * `directories` is a `Array` of directories to create
222
- * `files` is an `Array` of files to create
223
- * `files_if_missing` is an `Array` of files to create which should not be overwritten if they exist
224
- * `templates` is an `Array` of templates to render
225
- * `templates_if_missing` is an `Array` of templates to render which should not be overwritten if they exist
226
- * `fail_on_clobber` is a boolean accessor which causes generation to fail if any files in the `files` or `templates` arrays already exist. Defaults to true, but can be set to false by adding `-a clobber` to the `chef generate` command line
227
- * `report_actions` is a boolean accessor which causes the generator to report all of the actions it took
228
- * `next_steps` is a message to be displayed to the user as the last thing the generator does
229
-
230
- The distinction between files that are overwritten and those that are
231
- created only if they do not exist allows for updating a cookbook to an
232
- organization-wide policy while still allowing for per-cookbook
233
- customization.
234
-
235
- For example, if your cookbook template has a standard Rakefile and you wish
236
- to add a target to it, you can do so if Rakefile is in the `files` array.
237
- When the generator is used on top of an existing cookbook, the Rakefile will
238
- be rewritten. Custom rake tasks can be placed in `.rake` files in the
239
- directory `lib/tasks`, which will not be overwritten.
240
-
241
- Once the template object has been set up to your satisfaction, call the
242
- `#generate` method, which creates the Chef resources to generate your
243
- target.
244
-
245
- The list of files and templates take the path to the rendered file (e.g.
246
- `spec/spec_helper.rb`). The source for the file or template will be
247
- transformed by replacing foreward slashes and dots with underscores.
248
- Additionally, templates have `.erb` appended to the source.
249
-
250
- This code:
251
-
252
- template = ChefGen::Flavor::Amazing.new
253
- template.files << 'spec/spec_helper.rb'
254
- template.templates << '.rubocop.yml'
255
- template.generate
256
-
257
- is equivalent to manually creating these resources:
258
-
259
- file "#{cookbook_dir}/spec/spec_helper.rb" do
260
- source 'spec_spec_helper_rb'
261
- end
262
-
263
- template "#{cookbook_dir}/.rubocop.yml" do
264
- source '\_rubocop\_yml.erb'
265
- end
266
-
267
- ### TEMPLATE SNIPPETS
268
-
269
- Many templates will use common patterns, such as providing a README.md and
270
- CHANGELOG.md, providing the files necessary to create a ChefSpec unit
271
- testing suite, or the files necessary to create a Test Kitchen integration
272
- testing suite.
273
-
274
- Rather than have every template author create these, this gem ships with a
275
- number of snippets, which can be included in your plugin class like so:
276
-
277
- require 'chef_gen/flavor'
278
- require 'chef_gen/snippets'
279
-
280
- module ChefGen
281
- module Flavor
282
- class Amazing < FlavorBase
283
- include ChefGen::Snippet::ChefSpec
284
- end
285
- end
286
- end
287
-
288
- Snippets can add both declarations (files and templates to be rendered)
289
- and content. This reduces the amount of content that a flavor author
290
- has to include in their distribution.
291
-
292
- The snippets that ship with this gem are:
293
-
294
- * `CookbookBase` - sets up the basic files any cookbook needs (README, CHANGELOG, etc.)
295
- * `StyleFoodcritic` - sets up the files for style checking with Foodcritic
296
- * `StyleRubocop` - sets up the files for style checking with Rubocop
297
- * `StyleTailor` - sets up the files for style checking with Tailor
298
- * `ChefSpec` - sets up the files for basic ChefSpec unit testing
299
- * `TestKitchen` - sets up the files for basic Test Kitchen integration testing
300
- * `Recipes` - creates recipes/default.rb
301
- * `Attributes` - creates attributes/default.rb
302
- * `ExampleFile` - creates files/default/example.conf
303
- * `ExampleTemplate` - creates templates/default/example.conf.erb
304
- * `ResourceProvider` - sets up a sample LWRP resource and provider
305
-
306
- You can also create your own snippet. A snippet is simply a module that
307
- provides some number of public methods prefixed with `snippet\_`. Any such
308
- methods will be called, passing the recipe object as the only parameter when
309
- `#generate` is called. For example, a simplified ChefSpec snippet might look
310
- like this:
311
-
312
- module ChefGen
313
- module Snippet
314
- module ChefSpec
315
- def snippet_chefspec(recipe)
316
- @directories << 'spec'
317
- @directories << File.join('spec', '/recipes')
318
- @files << '.rspec'
319
- @files << File.join('spec', 'spec_helper.rb')
320
- @files << File.join('spec', 'recipes', 'default_spec.rb')
321
- end
322
- end
323
- end
324
- end
325
-
326
- ### SNIPPET INITIALIZERS
327
-
328
- Because you cannot add on to #initialize in a class when including a
329
- module, the FlavorBase initializer will call any public method provided
330
- by a snippet prefixed by `init\_`. For example, the StandardIgnore
331
- snippet initializes its list of patterns:
332
-
333
- ```
334
- # initializes the pattern arrays
335
- def init_standardignore_instancevars
336
- @chefignore_patterns = %w(
337
- .DS_Store Icon? nohup.out ehthumbs.db Thumbs.db
338
- .sasscache \#* .#* *~ *.sw[az] *.bak REVISION TAGS*
339
- tmtags *_flymake.* *_flymake *.tmproj .project .settings
340
- mkmf.log a.out *.o *.pyc *.so *.com *.class *.dll
341
- *.exe */rdoc/ .watchr test/* features/* Procfile
342
- .git */.git .gitignore .gitmodules .gitconfig .gitattributes
343
- .svn */.bzr/* */.hg/*
344
- )
345
- @gitignore_patterns = %w(
346
- Berksfile.lock *~ *# .#* \#*# .*.sw[az] *.un~
347
- bin/* .bundle/*
348
- )
164
+ end
349
165
  end
350
166
  ```
351
167
 
352
- ### AFTER SNIPPETS HOOK
353
-
354
- After all snippets have run, the method #after_run_snippets will be run
355
- if defined. This is useful to unwind or remove things in a derived
356
- flavor.
357
-
358
- ### SNIPPET CONTENT
359
-
360
- FlavorBase provides an #add_content method to allow snippets to create
361
- content. For example, the `Attributes` snippet is defined like this:
362
-
363
- ```
364
- module ChefGen
365
- module Snippet
366
- module Attributes
367
- def snippet_attributes_dirs(recipe)
368
- @directories << 'attributes'
369
- end
370
-
371
- def snippet_attributes_files(recipe)
372
- @templates_if_missing << File.join('attributes', 'default.rb')
373
- end
374
-
375
- def content_attribute_files(path)
376
- copy_snippet_file(
377
- File.join(
378
- File.dirname(__FILE__), '..', '..', '..',
379
- 'shared', 'snippet', 'attributes', 'attributes_default_rb.erb'
380
- ),
381
- File.join(path, 'templates', 'default', 'attributes_default_rb.erb')
168
+ The flavor is responsible for copying everything required to run
169
+ generation to that path by defining a `#add_content` method. For a
170
+ simple flavor, that might be just a recursive copy:
171
+
172
+ ```ruby
173
+ class ChefGen
174
+ module Flavor
175
+ class Awesome
176
+ ...
177
+ def add_content
178
+ FileUtils.cp_r(
179
+ File.expand_path(
180
+ File.join(
181
+ File.dirname(__FILE__),
182
+ '..', '..', '..', 'shared', 'flavor', NAME
183
+ )
184
+ ) + '/.',
185
+ @temp_path
382
186
  )
383
187
  end
384
188
  end
@@ -386,39 +190,16 @@ module ChefGen
386
190
  end
387
191
  ```
388
192
 
389
- When a flavor that includes this snippet is selected, the file
390
- `shared/snippet/attributes/attributes_default_rb.erb` is copied to
391
- the path `templates/default/attributes_default_rb.erb` in the temporary
392
- generator path.
393
-
394
- Look at the snippets in the `lib/chef_gen/snippet` directory and the
395
- [example flavor](https://github.com/Nordstrom/chef-gen-flavor-example)
396
- for an full demonstration of how these hooks work.
397
-
398
- ### SNIPPET DOCUMENTATION
399
-
400
- Some of the snippets provide extra functionality worth calling out:
401
-
402
- #### CookbookBase
193
+ Once the add_content method has been called, it is returned as the
194
+ value of `chefdk.generator_cookbook`, and generation proceeds as if
195
+ you had given `chef generate` and alternate path by passing -g.
403
196
 
404
- Provides several reader methods:
197
+ This path is cleaned up at exit unless the environment
198
+ variable `CHEFGEN_NOCLEANTMP` is set.
405
199
 
406
- * `cookbook_gems`, a hash of gem names to gem constraints. Flavors and other snippets can add to this list; all the gems are rendered to a Gemfile by this snippet
407
- * `gem_sources`, an array of gem source URL. This defaults to 'https://rubygems.org' and can be replaced or added onto
408
- * `berks_sources`, an array of Berksfile source URLs. This defaults to 'https://supermarket.chef.io' and can be replaced or added onto
409
- * `rake_tasks`, a hash of task names to task content. This allows snippets to add extra tasks to the Rakefile, which is rendered by this snippet
410
- * `guard_sets`, a hash of guard set names to set content. This allows snippets to add extra tasks to the Guardfile, which is rendered by this snippet
411
-
412
- Look at the content of these snippets for a better understanding of how
413
- to use these methods. For example, the ChefSpec snippet adds gems, rake
414
- tasks and guard sets.
415
-
416
- #### StandardIgnore
417
-
418
- Provides several reader methods:
419
-
420
- * `chefignore_patterns`, an array of patterns to write to the chefignore file
421
- * `gitignore_patterns`, an array of patterns to write to the .gitignore file
200
+ When using ChefGen::FlavorBase, there are helper functions to compose
201
+ the temporary directory from files that come from a mix of flavors and
202
+ reusable components.
422
203
 
423
204
  ## FEATURE TESTING FLAVORS
424
205
 
@@ -431,18 +212,20 @@ access these definitions, add the following line to your
431
212
 
432
213
  For an example of how to use these steps in your features, refer to the
433
214
  reference implementation of a flavor:
434
- [chef-gen-flavor-example](https://github.com/Nordstrom/chef-gen-flavor-example).
215
+ [chef-gen-flavor-example](https://github.com/jf647/chef-gen-flavor-example).
435
216
 
436
217
  Documentation for the steps themselves is in the file `ARUBA_STEPS.md`
437
218
 
438
219
  ## AUTHOR
439
220
 
440
- James FitzGibbon - james.i.fitzgibbon@nordstrom.com - Nordstrom, Inc.
221
+ [James FitzGibbon](https://github.com/jf647)
441
222
 
442
223
  ## LICENSE
443
224
 
444
225
  Copyright 2015 Nordstrom, Inc.
445
226
 
227
+ Copyright 2015 James FitzGibbon
228
+
446
229
  Licensed under the Apache License, Version 2.0 (the "License"); you may not
447
230
  use this file except in compliance with the License. You may obtain a copy
448
231
  of the License at