chef-gen-flavors 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/ARUBA_STEPS.md +74 -0
  3. data/History.md +16 -0
  4. data/Manifest.txt +25 -30
  5. data/README.md +121 -16
  6. data/chef-gen-flavors.gemspec +8 -5
  7. data/lib/chef_gen/flavor_base.rb +42 -34
  8. data/lib/chef_gen/flavors.rb +36 -10
  9. data/lib/chef_gen/snippet/attributes.rb +13 -0
  10. data/lib/chef_gen/snippet/chef_spec.rb +84 -14
  11. data/lib/chef_gen/snippet/cookbook_base.rb +109 -23
  12. data/lib/chef_gen/snippet/example_file.rb +15 -0
  13. data/lib/chef_gen/snippet/example_template.rb +15 -0
  14. data/lib/chef_gen/snippet/git_init.rb +2 -0
  15. data/lib/chef_gen/snippet/recipes.rb +15 -0
  16. data/lib/chef_gen/snippet/resource_provider.rb +18 -0
  17. data/lib/chef_gen/snippet/standard_ignore.rb +56 -80
  18. data/lib/chef_gen/snippet/style_foodcritic.rb +51 -0
  19. data/lib/chef_gen/snippet/style_rubocop.rb +80 -0
  20. data/lib/chef_gen/snippet/style_tailor.rb +48 -0
  21. data/lib/chef_gen/snippet/test_kitchen.rb +70 -15
  22. data/lib/chef_gen/snippets.rb +2 -0
  23. data/shared/snippet/attributes/attributes_default_rb.erb +8 -0
  24. data/{.rspec → shared/snippet/chef_spec/_rspec.erb} +0 -0
  25. data/shared/snippet/chef_spec/spec_chef_runner_context_rb.erb +36 -0
  26. data/shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb +7 -0
  27. data/shared/snippet/chef_spec/spec_spec_helper_rb.erb +95 -0
  28. data/shared/snippet/cookbookbase/Berksfile.erb +5 -0
  29. data/shared/snippet/cookbookbase/CHANGELOG_md.erb +5 -0
  30. data/shared/snippet/cookbookbase/Gemfile.erb +7 -0
  31. data/shared/snippet/cookbookbase/Guardfile.erb +10 -0
  32. data/shared/snippet/cookbookbase/README_md.erb +92 -0
  33. data/shared/snippet/cookbookbase/Rakefile.erb +20 -0
  34. data/shared/snippet/cookbookbase/metadata_rb.erb +10 -0
  35. data/shared/snippet/examplefile/files_default_example_conf +34 -0
  36. data/shared/snippet/exampletemplate/templates_default_example_conf_erb +22 -0
  37. data/shared/snippet/recipes/recipes_default_rb.erb +9 -0
  38. data/shared/snippet/resourceprovider/providers_default_rb.erb +20 -0
  39. data/shared/snippet/resourceprovider/resources_default_rb.erb +9 -0
  40. data/shared/snippet/stylerubocop/_rubocop_yml.erb +27 -0
  41. data/shared/snippet/testkitchen/_kitchen_yml.erb +30 -0
  42. data/shared/snippet/testkitchen/libraries_kitchen_helper_rb +13 -0
  43. data/shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb +16 -0
  44. data/shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb +7 -0
  45. metadata +42 -32
  46. data/.rubocop.yml +0 -27
  47. data/.travis.yml +0 -6
  48. data/Gemfile +0 -3
  49. data/Guardfile +0 -15
  50. data/Rakefile +0 -98
  51. data/features/generate.feature +0 -17
  52. data/features/support/env.rb +0 -15
  53. data/spec/lib/chef_gen/flavor_base_spec.rb +0 -167
  54. data/spec/lib/chef_gen/flavors_spec.rb +0 -132
  55. data/spec/lib/chef_gen/snippet/attributes_spec.rb +0 -40
  56. data/spec/lib/chef_gen/snippet/chef_spec_spec.rb +0 -40
  57. data/spec/lib/chef_gen/snippet/cookbook_base_spec.rb +0 -32
  58. data/spec/lib/chef_gen/snippet/example_file_spec.rb +0 -40
  59. data/spec/lib/chef_gen/snippet/example_template_spec.rb +0 -40
  60. data/spec/lib/chef_gen/snippet/git_init_spec.rb +0 -30
  61. data/spec/lib/chef_gen/snippet/recipes_spec.rb +0 -40
  62. data/spec/lib/chef_gen/snippet/resource_provider_spec.rb +0 -40
  63. data/spec/lib/chef_gen/snippet/standard_ignore_spec.rb +0 -35
  64. data/spec/lib/chef_gen/snippet/style_rubocop_spec.rb +0 -31
  65. data/spec/lib/chef_gen/snippet/test_kitchen_spec.rb +0 -44
  66. data/spec/spec_helper.rb +0 -64
  67. data/spec/support/fixtures/code_generator/metadata.rb +0 -2
  68. data/spec/support/fixtures/code_generator/recipes/cookbook.rb +0 -1
  69. data/spec/support/fixtures/code_generator_2/metadata.rb +0 -2
  70. data/spec/support/fixtures/code_generator_2/recipes/cookbook.rb +0 -3
  71. data/spec/support/fixtures/code_generator_2/templates/default/README_md.erb +0 -1
  72. data/spec/support/fixtures/lib/chef_gen/flavor/bar.rb +0 -21
  73. data/spec/support/fixtures/lib/chef_gen/flavor/baz.rb +0 -6
  74. data/spec/support/fixtures/lib/chef_gen/flavor/foo.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d54346e43941b8b363187f320e7a4e79e88d01c7
4
- data.tar.gz: 9c2277aea6a1ce7cc542491469bb2ca07329a65c
3
+ metadata.gz: f986fa7d81233486a88d6010323746dc1ca359ef
4
+ data.tar.gz: 70605598307fb2db0301044b2b38ce41105c3c91
5
5
  SHA512:
6
- metadata.gz: 5f4ff7d350bcfe5bf7f0d662bf898fa8d1ed5a3d6b21417da090320011fe7e4878648c48596d949c87cd376cfd85d829be1c71fc071d2b75aa5d2b1fcef9dd5c
7
- data.tar.gz: 174388c2872ecbbea6820f355648b82c8ef918a57d4585ef263b84601c2372f2d3d57998ad5cf81534c1ea935d3fae0c166321fecff3ad43570c48d1d2444859
6
+ metadata.gz: a7e46da100ad456de5d3c5496f5da32dcfb953c0c969d897f9f1d3135a99b76d1b0e8eb40aea1fccdd9d222119e180b1e25f477bc0abba986aad9a933969d270
7
+ data.tar.gz: b0495ba337a03df57cb01d9fb5a694aa88ae037ac2c2ead79dad5b816344d97bab42160ffd5b41a1685d7706c959fe39563f86a75808b6ca4f9e946775f078fc
data/ARUBA_STEPS.md ADDED
@@ -0,0 +1,74 @@
1
+ # Aruba step definitions for feature testing flavors
2
+
3
+ chef-gen-flavors provides a number of useful Aruba step definitions to help
4
+ test your flavors.
5
+
6
+ Aruba is a CLI driver for Cucumber. It works off of the same feature files
7
+ you may be used to using in Capybara for web app testing (though the steps
8
+ are perforce quite different).
9
+
10
+ To access these definitions,
11
+ add the following line to your `features/support/env.rb` file:
12
+
13
+ require 'chef_gen/flavors/cucumber'
14
+
15
+ For an example of how to use these steps in your features, refer to the
16
+ reference implementation of a flavor:
17
+ [chef-gen-flavor-example](https://github.com/Nordstrom/chef-gen-flavor-example).
18
+
19
+ ## knife
20
+
21
+ Given a knife.rb that uses chef-gen-flavors
22
+
23
+ Creates a simple knife.rb that requires chef-gen-flavors:
24
+
25
+ require 'chef_gen/flavors'
26
+ chefdk.generator_cookbook = ChefGen::Flavors.path
27
+
28
+ ## chefdk
29
+
30
+ When I generate a cookbook named "foo"
31
+ When I generate a cookbook named "foo" with the "-a bar=baz" option
32
+
33
+ Generates a cookbook using `chef generate cookbook`, optionally with
34
+ additional command line args. To ensure that you do not get a prompt, you
35
+ should first select your flavor using environment variables:
36
+
37
+ And I set the environment variables to:
38
+ | variable | value |
39
+ |----------------|----------|
40
+ | CHEFGEN_FLAVOR | myflavor |
41
+
42
+ ## bundle
43
+
44
+ When I bundle gems
45
+
46
+ Runs 'bundle' after unsetting the bundler environment variables (so that you
47
+ use the bundle that belongs to your generated artifact, not the bundle of
48
+ your flavor gem).
49
+
50
+ ## rake
51
+
52
+ When I run a style test
53
+ When I run a unit test
54
+
55
+ Runs 'bundle exec rake style' or 'bundle exec rake spec'
56
+
57
+ When I list the rake tasks
58
+
59
+ Runs 'bundle exec rake -T'
60
+
61
+ ## kitchen
62
+
63
+ When I list the kitchen suites
64
+
65
+ Runs 'bundle exec kitchen list'
66
+
67
+ ## regex
68
+
69
+ Then the output should match each of:
70
+ | ^regex1 |
71
+ | regex2$ |
72
+
73
+ Not really a chef-gen-flavors step, but provides a simple way to check
74
+ multiple regexes against the output.
data/History.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog for chef-gen-flavors
2
2
 
3
+ ## 0.7.0
4
+
5
+ Major re-organization around snippets
6
+
7
+ * the code generator cookbook is now copied to a temporary directory that snippets can augment
8
+ * snippets can therefore write content as well as file declarations. All of the core snippets have been enhanced to do this, so the example cookbook is now tiny.
9
+ * add hooks for snippets to initialize themselves
10
+ * add a hook after all snippets have run in case mods want to rewind or undo things that other snippets have done
11
+ * add the version of the flavor to the description in the menu
12
+ * enhance the cookbook base snippet to allow the Rakefile to be composed of content from other snippets
13
+ * enhance the cookbook base snippet to allow the Gemfile to be composed of content from other snippets
14
+ * enhance the cookbook base snippet to allow the Guardfile to be composed of content from other snippets
15
+ * move the chefignore/gitignore accumulators out of FlavorBase and into the StandardIgnore snippet
16
+ * extract FoodCritic to its own snippet
17
+ * add a StyleTailor snippet
18
+
3
19
  ## 0.6.2
4
20
 
5
21
  * sort flavors alphabetically (suggested by @echohack)
data/Manifest.txt CHANGED
@@ -1,16 +1,9 @@
1
- .rspec
2
- .rubocop.yml
3
- .travis.yml
4
- Gemfile
5
- Guardfile
1
+ ARUBA_STEPS.md
6
2
  History.md
7
3
  LICENSE
8
4
  Manifest.txt
9
5
  README.md
10
- Rakefile
11
6
  chef-gen-flavors.gemspec
12
- features/generate.feature
13
- features/support/env.rb
14
7
  lib/chef_gen/flavor.rb
15
8
  lib/chef_gen/flavor_base.rb
16
9
  lib/chef_gen/flavors.rb
@@ -30,28 +23,30 @@ lib/chef_gen/snippet/git_init.rb
30
23
  lib/chef_gen/snippet/recipes.rb
31
24
  lib/chef_gen/snippet/resource_provider.rb
32
25
  lib/chef_gen/snippet/standard_ignore.rb
26
+ lib/chef_gen/snippet/style_foodcritic.rb
33
27
  lib/chef_gen/snippet/style_rubocop.rb
28
+ lib/chef_gen/snippet/style_tailor.rb
34
29
  lib/chef_gen/snippet/test_kitchen.rb
35
30
  lib/chef_gen/snippets.rb
36
- spec/lib/chef_gen/flavor_base_spec.rb
37
- spec/lib/chef_gen/flavors_spec.rb
38
- spec/lib/chef_gen/snippet/attributes_spec.rb
39
- spec/lib/chef_gen/snippet/chef_spec_spec.rb
40
- spec/lib/chef_gen/snippet/cookbook_base_spec.rb
41
- spec/lib/chef_gen/snippet/example_file_spec.rb
42
- spec/lib/chef_gen/snippet/example_template_spec.rb
43
- spec/lib/chef_gen/snippet/git_init_spec.rb
44
- spec/lib/chef_gen/snippet/recipes_spec.rb
45
- spec/lib/chef_gen/snippet/resource_provider_spec.rb
46
- spec/lib/chef_gen/snippet/standard_ignore_spec.rb
47
- spec/lib/chef_gen/snippet/style_rubocop_spec.rb
48
- spec/lib/chef_gen/snippet/test_kitchen_spec.rb
49
- spec/spec_helper.rb
50
- spec/support/fixtures/code_generator/metadata.rb
51
- spec/support/fixtures/code_generator/recipes/cookbook.rb
52
- spec/support/fixtures/code_generator_2/metadata.rb
53
- spec/support/fixtures/code_generator_2/recipes/cookbook.rb
54
- spec/support/fixtures/code_generator_2/templates/default/README_md.erb
55
- spec/support/fixtures/lib/chef_gen/flavor/bar.rb
56
- spec/support/fixtures/lib/chef_gen/flavor/baz.rb
57
- spec/support/fixtures/lib/chef_gen/flavor/foo.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
@@ -3,7 +3,7 @@
3
3
  * home :: https://github.com/Nordstrom/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 :: [![Build Status](https://travis-ci.org/Nordstrom/chef-gen-flavors.png?branch=master)](https://travis-ci.org/Nordstrom/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
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
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
9
 
@@ -52,10 +52,10 @@ than one plugin is found, you will be prompted as to which you want to use:
52
52
 
53
53
  $ chef generate cookbook my_app
54
54
 
55
- If you set the environment variable `CHEFGEN_TEMPLATE` to the name of a
55
+ If you set the environment variable `CHEFGEN_FLAVOR` to the name of a
56
56
  plugin, it will be chosen instead of presenting a prompt:
57
57
 
58
- $ CHEFGEN_TEMPLATE=mytemplate chef generate cookbook my_app
58
+ $ CHEFGEN_FLAVOR=mytemplate chef generate cookbook my_app
59
59
 
60
60
  ## USING THE BUILT-IN CHEFDK TEMPLATE
61
61
 
@@ -167,13 +167,15 @@ generator cookbook to a temporary path, which is what gets returned
167
167
  and used by ChefDK. This path is cleaned up at exit unless the environment
168
168
  variable CHEFGEN_NOCLEANTMP is set.
169
169
 
170
- This temporary path is set as an attribute in the ChefDK Generator
171
- context, and can be retrieved in a flavor by calling
170
+ ## ADDING CONTENT TO THE GENERATOR COPY
172
171
 
173
- ChefDK::Generator.context.generator_path
172
+ After the generator is copied to a temporary path, the #add_content
173
+ instance method is called (if it exists) on the flavor class. It is
174
+ passed one arg: the path to the temporary copy.
174
175
 
175
- This is foundational work to allow snippets to include content as well
176
- as declarations of what files they will render.
176
+ This allows flavors to create content dynamically by writing files
177
+ to the proper directly. It is exploited by the flavor base class
178
+ described below.
177
179
 
178
180
  ## FLAVOR BASE CLASS
179
181
 
@@ -216,8 +218,6 @@ The plugin has several helper methods you can use:
216
218
  * `files_if_missing` is an `Array` of files to create which should not be overwritten if they exist
217
219
  * `templates` is an `Array` of templates to render
218
220
  * `templates_if_missing` is an `Array` of templates to render which should not be overwritten if they exist
219
- * `chefignore_files` is an `Array` of glob patterns to write to the `chefignore` file. If this array is empty, the file is not created automatically (but templates can take this on themselves)
220
- * `gitignore_files` is an `Array` of glob patterns to write to the `.gitignore` file. If this array is empty, the file is not created automatically (but templates can take this on themselves)
221
221
  * `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
222
222
  * `report_actions` is a boolean accessor which causes the generator to report all of the actions it took
223
223
  * `next_steps` is a message to be displayed to the user as the last thing the generator does
@@ -256,7 +256,7 @@ is equivalent to manually creating these resources:
256
256
  end
257
257
 
258
258
  template "#{cookbook_dir}/.rubocop.yml" do
259
- source '_rubocop_yml.erb'
259
+ source '\_rubocop\_yml.erb'
260
260
  end
261
261
 
262
262
  ### TEMPLATE SNIPPETS
@@ -280,10 +280,16 @@ number of snippets, which can be included in your plugin class like so:
280
280
  end
281
281
  end
282
282
 
283
+ Snippets can add both declarations (files and templates to be rendered)
284
+ and content. This reduces the amount of content that a flavor author
285
+ has to include in their distribution.
286
+
283
287
  The snippets that ship with this gem are:
284
288
 
285
289
  * `CookbookBase` - sets up the basic files any cookbook needs (README, CHANGELOG, etc.)
290
+ * `StyleFoodcritic` - sets up the files for style checking with Foodcritic
286
291
  * `StyleRubocop` - sets up the files for style checking with Rubocop
292
+ * `StyleTailor` - sets up the files for style checking with Tailor
287
293
  * `ChefSpec` - sets up the files for basic ChefSpec unit testing
288
294
  * `TestKitchen` - sets up the files for basic Test Kitchen integration testing
289
295
  * `Recipes` - creates recipes/default.rb
@@ -312,16 +318,115 @@ like this:
312
318
  end
313
319
  end
314
320
 
321
+ ### SNIPPET INITIALIZERS
322
+
323
+ Because you cannot add on to #initialize in a class when including a
324
+ module, the FlavorBase initializer will call any public method provided
325
+ by a snippet prefixed by `init\_`. For example, the StandardIgnore
326
+ snippet initializes its list of patterns:
327
+
328
+ ```
329
+ # initializes the pattern arrays
330
+ def init_standardignore_instancevars
331
+ @chefignore_patterns = %w(
332
+ .DS_Store Icon? nohup.out ehthumbs.db Thumbs.db
333
+ .sasscache \#* .#* *~ *.sw[az] *.bak REVISION TAGS*
334
+ tmtags *_flymake.* *_flymake *.tmproj .project .settings
335
+ mkmf.log a.out *.o *.pyc *.so *.com *.class *.dll
336
+ *.exe */rdoc/ .watchr test/* features/* Procfile
337
+ .git */.git .gitignore .gitmodules .gitconfig .gitattributes
338
+ .svn */.bzr/* */.hg/*
339
+ )
340
+ @gitignore_patterns = %w(
341
+ Berksfile.lock *~ *# .#* \#*# .*.sw[az] *.un~
342
+ bin/* .bundle/*
343
+ )
344
+ end
345
+ ```
346
+
347
+ ### AFTER SNIPPETS HOOK
348
+
349
+ After all snippets have run, the method #after_run_snippets will be run
350
+ if defined. This is useful to unwind or remove things in a derived
351
+ flavor.
352
+
353
+ ### SNIPPET CONTENT
354
+
355
+ FlavorBase provides an #add_content method to allow snippets to create
356
+ content. For example, the `Attributes` snippet is defined like this:
357
+
358
+ ```
359
+ module ChefGen
360
+ module Snippet
361
+ module Attributes
362
+ def snippet_attributes_dirs(recipe)
363
+ @directories << 'attributes'
364
+ end
365
+
366
+ def snippet_attributes_files(recipe)
367
+ @templates_if_missing << File.join('attributes', 'default.rb')
368
+ end
369
+
370
+ def content_attribute_files(path)
371
+ copy_snippet_file(
372
+ File.join(
373
+ File.dirname(__FILE__), '..', '..', '..',
374
+ 'shared', 'snippet', 'attributes', 'attributes_default_rb.erb'
375
+ ),
376
+ File.join(path, 'templates', 'default', 'attributes_default_rb.erb')
377
+ )
378
+ end
379
+ end
380
+ end
381
+ end
382
+ ```
383
+
384
+ When a flavor that includes this snippet is selected, the file
385
+ `shared/snippet/attributes/attributes_default_rb.erb` is copied to
386
+ the path `templates/default/attributes_default_rb.erb` in the temporary
387
+ generator path.
388
+
389
+ Look at the snippets in the `lib/chef_gen/snippet` directory and the
390
+ [example flavor](https://github.com/Nordstrom/chef-gen-flavor-example)
391
+ for an full demonstration of how these hooks work.
392
+
393
+ ### SNIPPET DOCUMENTATION
394
+
395
+ Some of the snippets provide extra functionality worth calling out:
396
+
397
+ #### CookbookBase
398
+
399
+ Provides several reader methods:
400
+
401
+ * `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
402
+ * `gem_sources`, an array of gem source URL. This defaults to 'https://rubygems.org' and can be replaced or added onto
403
+ * `berks_sources`, an array of Berksfile source URLs. This defaults to 'https://supermarket.chef.io' and can be replaced or added onto
404
+ * `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
405
+ * `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
406
+
407
+ Look at the content of these snippets for a better understanding of how
408
+ to use these methods. For example, the ChefSpec snippet adds gems, rake
409
+ tasks and guard sets.
410
+
411
+ #### StandardIgnore
412
+
413
+ Provides several reader methods:
414
+
415
+ * `chefignore_patterns`, an array of patterns to write to the chefignore file
416
+ * `gitignore_patterns`, an array of patterns to write to the .gitignore file
417
+
315
418
  ## FEATURE TESTING FLAVORS
316
419
 
317
- chef-gen-flavors provides a number of useful step definitions for Aruba (a CLI
318
- driver for Cucumber) to make it easier to test flavors. To access these definitions,
319
- add the following line to your `features/support/env.rb` file:
420
+ chef-gen-flavors provides a number of useful step definitions for Aruba
421
+ (a CLI driver for Cucumber) to make it easier to test flavors. To
422
+ access these definitions, add the following line to your
423
+ `features/support/env.rb` file:
320
424
 
321
425
  require 'chef_gen/flavors/cucumber'
322
426
 
323
- For an example of how to use these steps in your features, refer to the reference
324
- implementation of a flavor: [chef-gen-flavor-example](https://github.com/Nordstrom/chef-gen-flavor-example).
427
+ For an example of how to use these steps in your features, refer to the
428
+ reference implementation of a flavor:
429
+ [chef-gen-flavor-example](https://github.com/Nordstrom/chef-gen-flavor-example).
325
430
 
326
431
  Documentation for the steps themselves is in the file `ARUBA_STEPS.md`
327
432
 
@@ -1,18 +1,18 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: chef-gen-flavors 0.6.2.20150605071048 ruby lib
2
+ # stub: chef-gen-flavors 0.7.0.20150609141116 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "chef-gen-flavors"
6
- s.version = "0.6.2.20150605071048"
6
+ s.version = "0.7.0.20150609141116"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["James FitzGibbon"]
11
- s.date = "2015-06-05"
11
+ s.date = "2015-06-09"
12
12
  s.description = "chef-gen-flavors is a framework for creating custom templates for the\n'chef generate' command provided by ChefDK.\n\nThis gem simply provides a framework; templates are provided by separate\ngems, which you can host privately for use within your organization or\npublicly for the Chef community to use.\n\nAt present this is focused primarily on providing templates for generation of\ncookbooks, as this is where most organization-specific customization takes place.\nSupport for the other artifacts that ChefDK can generate may work, but is not\nthe focus of early releases."
13
13
  s.email = ["james.i.fitzgibbon@nordstrom.com"]
14
- s.extra_rdoc_files = ["History.md", "Manifest.txt", "README.md"]
15
- s.files = [".rspec", ".rubocop.yml", ".travis.yml", "Gemfile", "Guardfile", "History.md", "LICENSE", "Manifest.txt", "README.md", "Rakefile", "chef-gen-flavors.gemspec", "features/generate.feature", "features/support/env.rb", "lib/chef_gen/flavor.rb", "lib/chef_gen/flavor_base.rb", "lib/chef_gen/flavors.rb", "lib/chef_gen/flavors/cucumber.rb", "lib/chef_gen/flavors/cucumber/bundle.rb", "lib/chef_gen/flavors/cucumber/chefdk.rb", "lib/chef_gen/flavors/cucumber/kitchen.rb", "lib/chef_gen/flavors/cucumber/knife.rb", "lib/chef_gen/flavors/cucumber/rake.rb", "lib/chef_gen/flavors/cucumber/regex.rb", "lib/chef_gen/snippet/attributes.rb", "lib/chef_gen/snippet/chef_spec.rb", "lib/chef_gen/snippet/cookbook_base.rb", "lib/chef_gen/snippet/example_file.rb", "lib/chef_gen/snippet/example_template.rb", "lib/chef_gen/snippet/git_init.rb", "lib/chef_gen/snippet/recipes.rb", "lib/chef_gen/snippet/resource_provider.rb", "lib/chef_gen/snippet/standard_ignore.rb", "lib/chef_gen/snippet/style_rubocop.rb", "lib/chef_gen/snippet/test_kitchen.rb", "lib/chef_gen/snippets.rb", "spec/lib/chef_gen/flavor_base_spec.rb", "spec/lib/chef_gen/flavors_spec.rb", "spec/lib/chef_gen/snippet/attributes_spec.rb", "spec/lib/chef_gen/snippet/chef_spec_spec.rb", "spec/lib/chef_gen/snippet/cookbook_base_spec.rb", "spec/lib/chef_gen/snippet/example_file_spec.rb", "spec/lib/chef_gen/snippet/example_template_spec.rb", "spec/lib/chef_gen/snippet/git_init_spec.rb", "spec/lib/chef_gen/snippet/recipes_spec.rb", "spec/lib/chef_gen/snippet/resource_provider_spec.rb", "spec/lib/chef_gen/snippet/standard_ignore_spec.rb", "spec/lib/chef_gen/snippet/style_rubocop_spec.rb", "spec/lib/chef_gen/snippet/test_kitchen_spec.rb", "spec/spec_helper.rb", "spec/support/fixtures/code_generator/metadata.rb", "spec/support/fixtures/code_generator/recipes/cookbook.rb", "spec/support/fixtures/code_generator_2/metadata.rb", "spec/support/fixtures/code_generator_2/recipes/cookbook.rb", "spec/support/fixtures/code_generator_2/templates/default/README_md.erb", "spec/support/fixtures/lib/chef_gen/flavor/bar.rb", "spec/support/fixtures/lib/chef_gen/flavor/baz.rb", "spec/support/fixtures/lib/chef_gen/flavor/foo.rb"]
14
+ s.extra_rdoc_files = ["ARUBA_STEPS.md", "History.md", "Manifest.txt", "README.md"]
15
+ s.files = ["ARUBA_STEPS.md", "History.md", "LICENSE", "Manifest.txt", "README.md", "chef-gen-flavors.gemspec", "lib/chef_gen/flavor.rb", "lib/chef_gen/flavor_base.rb", "lib/chef_gen/flavors.rb", "lib/chef_gen/flavors/cucumber.rb", "lib/chef_gen/flavors/cucumber/bundle.rb", "lib/chef_gen/flavors/cucumber/chefdk.rb", "lib/chef_gen/flavors/cucumber/kitchen.rb", "lib/chef_gen/flavors/cucumber/knife.rb", "lib/chef_gen/flavors/cucumber/rake.rb", "lib/chef_gen/flavors/cucumber/regex.rb", "lib/chef_gen/snippet/attributes.rb", "lib/chef_gen/snippet/chef_spec.rb", "lib/chef_gen/snippet/cookbook_base.rb", "lib/chef_gen/snippet/example_file.rb", "lib/chef_gen/snippet/example_template.rb", "lib/chef_gen/snippet/git_init.rb", "lib/chef_gen/snippet/recipes.rb", "lib/chef_gen/snippet/resource_provider.rb", "lib/chef_gen/snippet/standard_ignore.rb", "lib/chef_gen/snippet/style_foodcritic.rb", "lib/chef_gen/snippet/style_rubocop.rb", "lib/chef_gen/snippet/style_tailor.rb", "lib/chef_gen/snippet/test_kitchen.rb", "lib/chef_gen/snippets.rb", "shared/snippet/attributes/attributes_default_rb.erb", "shared/snippet/chef_spec/_rspec.erb", "shared/snippet/chef_spec/spec_chef_runner_context_rb.erb", "shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb", "shared/snippet/chef_spec/spec_spec_helper_rb.erb", "shared/snippet/cookbookbase/Berksfile.erb", "shared/snippet/cookbookbase/CHANGELOG_md.erb", "shared/snippet/cookbookbase/Gemfile.erb", "shared/snippet/cookbookbase/Guardfile.erb", "shared/snippet/cookbookbase/README_md.erb", "shared/snippet/cookbookbase/Rakefile.erb", "shared/snippet/cookbookbase/metadata_rb.erb", "shared/snippet/examplefile/files_default_example_conf", "shared/snippet/exampletemplate/templates_default_example_conf_erb", "shared/snippet/recipes/recipes_default_rb.erb", "shared/snippet/resourceprovider/providers_default_rb.erb", "shared/snippet/resourceprovider/resources_default_rb.erb", "shared/snippet/stylerubocop/_rubocop_yml.erb", "shared/snippet/testkitchen/_kitchen_yml.erb", "shared/snippet/testkitchen/libraries_kitchen_helper_rb", "shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb", "shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb"]
16
16
  s.homepage = "https://github.com/Nordstrom/chef-gen-flavors"
17
17
  s.licenses = ["apache2"]
18
18
  s.rdoc_options = ["--main", "README.md"]
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency(%q<yard>, ["~> 0.8"])
41
41
  s.add_development_dependency(%q<aruba>, ["~> 0.6"])
42
42
  s.add_development_dependency(%q<rspec_junit_formatter>, ["~> 0.2"])
43
+ s.add_development_dependency(%q<fakefs>, ["~> 0.6"])
43
44
  else
44
45
  s.add_dependency(%q<little-plugger>, ["~> 1.1"])
45
46
  s.add_dependency(%q<bogo-ui>, ["~> 0.1"])
@@ -58,6 +59,7 @@ Gem::Specification.new do |s|
58
59
  s.add_dependency(%q<yard>, ["~> 0.8"])
59
60
  s.add_dependency(%q<aruba>, ["~> 0.6"])
60
61
  s.add_dependency(%q<rspec_junit_formatter>, ["~> 0.2"])
62
+ s.add_dependency(%q<fakefs>, ["~> 0.6"])
61
63
  end
62
64
  else
63
65
  s.add_dependency(%q<little-plugger>, ["~> 1.1"])
@@ -77,5 +79,6 @@ Gem::Specification.new do |s|
77
79
  s.add_dependency(%q<yard>, ["~> 0.8"])
78
80
  s.add_dependency(%q<aruba>, ["~> 0.6"])
79
81
  s.add_dependency(%q<rspec_junit_formatter>, ["~> 0.2"])
82
+ s.add_dependency(%q<fakefs>, ["~> 0.6"])
80
83
  end
81
84
  end
@@ -11,14 +11,6 @@ module ChefGen
11
11
  # @return [Array] list of directories
12
12
  attr_reader :directories
13
13
 
14
- # the file patterns to write to the chefignore files
15
- # @return [Array] list of file patterns
16
- attr_reader :chefignore_files
17
-
18
- # the file patterns to add to .gitignore
19
- # @return [Array] list of file patterns
20
- attr_reader :gitignore_files
21
-
22
14
  # files to create unconditionally
23
15
  # @return [Array] list of destination filenames
24
16
  attr_reader :files
@@ -65,11 +57,38 @@ module ChefGen
65
57
  @report_actions = true
66
58
  @fail_on_clobber = !ctx.respond_to?(:clobber)
67
59
  @directories = []
68
- %w(files files_if_missing templates templates_if_missing
69
- chefignore_files gitignore_files actions_taken failures)
70
- .each do |varname|
60
+ %w(directories files files_if_missing templates
61
+ templates_if_missing actions_taken failures).each do |varname|
71
62
  instance_variable_set("@#{varname}".to_sym, [])
72
63
  end
64
+
65
+ # call initializers defined by snippets
66
+ methods_by_pattern(/^init_/).each do |m|
67
+ send(m)
68
+ end
69
+ end
70
+
71
+ # find all public methods of the flavor starting with content_
72
+ # and calls them, passing the path as the sole parameter
73
+ # @param path [String] the path to the copy of the generator cookbook
74
+ # @return [void]
75
+ def add_content(path)
76
+ methods_by_pattern(/^content_/).each do |m|
77
+ send(m, path)
78
+ end
79
+ end
80
+
81
+ # copy a snippet content file to the temporary generator path,
82
+ # creating the destination directory if it does not already exist
83
+ # @param src [String] the source file
84
+ # @param dst [String] the destination file
85
+ # @return [void]
86
+ def copy_snippet_file(src, dst)
87
+ # make sure the parent of the destination exists
88
+ parent = File.dirname(dst)
89
+ FileUtils.mkpath(parent) unless Dir.exist?(parent)
90
+ # copy the file
91
+ FileUtils.copy_file(src, dst)
73
92
  end
74
93
 
75
94
  # a proxy to ChefDK's generator context
@@ -83,6 +102,7 @@ module ChefGen
83
102
  def generate
84
103
  add_target_path
85
104
  run_snippets
105
+ after_run_snippets if respond_to?(:after_run_snippets)
86
106
  add_directories
87
107
  add_files
88
108
  add_templates
@@ -90,8 +110,6 @@ module ChefGen
90
110
  @failures.each { |f| $stderr.puts f }
91
111
  fail 'errors during generation'
92
112
  end
93
- build_ignore('.gitignore', @gitignore_files)
94
- build_ignore('chefignore', @chefignore_files)
95
113
  report_actions_taken(@actions_taken) \
96
114
  if @report_actions && @actions_taken
97
115
  display_next_steps(@next_steps) if @next_steps
@@ -116,21 +134,27 @@ module ChefGen
116
134
  @actions_taken << "create directory #{@target_path}"
117
135
  end
118
136
 
119
- # find all public methods of the plugin starting with snippet_
137
+ # find all public methods of the flavor starting with snippet_
120
138
  # and calls them
121
139
  # @return [void]
122
140
  # @yield [Chef::Recipe] the recipe into which the mixin can inject
123
141
  # resources
124
142
  # @api private
125
143
  def run_snippets
126
- snippets = public_methods.select do |m|
127
- m.to_s =~ /^snippet_/
128
- end
129
- snippets.each do |m|
144
+ methods_by_pattern(/^snippet_/).each do |m|
130
145
  send(m, @recipe)
131
146
  end
132
147
  end
133
148
 
149
+ # returns a list of public methods that match a pattern
150
+ # @param pattern [Regexp] the pattern to match methods against
151
+ # @return [Array] a list of sorted methods
152
+ def methods_by_pattern(pattern)
153
+ public_methods.select do |m|
154
+ m.to_s =~ pattern
155
+ end
156
+ end
157
+
134
158
  # declares a directory resource for each element of @directories
135
159
  # @return [void]
136
160
  # @api private
@@ -197,22 +221,6 @@ module ChefGen
197
221
  end
198
222
  end
199
223
 
200
- # creates a .gitignore or chefignore file
201
- # @param dstfile [String] the destination file
202
- # @param files [Array] an array of lines to write to the file
203
- # @return [void]
204
- # @api private
205
- def build_ignore(dstfile, files)
206
- return if files.empty?
207
- dst = File.join(@target_path, dstfile)
208
- @recipe.send(:file, dst) do
209
- # :nocov:
210
- content files.flatten.join("\n")
211
- # :nocov:
212
- end
213
- @actions_taken << "create ignore file #{dst}"
214
- end
215
-
216
224
  # reports on the actions taken by the plugin
217
225
  # @param actions [Array] the list of actions taken
218
226
  # @return [void]