chef-gen-flavors 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f986fa7d81233486a88d6010323746dc1ca359ef
4
- data.tar.gz: 70605598307fb2db0301044b2b38ce41105c3c91
3
+ metadata.gz: fdf1906af1dbba1c06bbea05337a3014905994dc
4
+ data.tar.gz: 32c134e20c8c23c093010ed8ba1fe138c7af14ef
5
5
  SHA512:
6
- metadata.gz: a7e46da100ad456de5d3c5496f5da32dcfb953c0c969d897f9f1d3135a99b76d1b0e8eb40aea1fccdd9d222119e180b1e25f477bc0abba986aad9a933969d270
7
- data.tar.gz: b0495ba337a03df57cb01d9fb5a694aa88ae037ac2c2ead79dad5b816344d97bab42160ffd5b41a1685d7706c959fe39563f86a75808b6ca4f9e946775f078fc
6
+ metadata.gz: 82cb00c61ab851036a62ed662d2d8b6402e619d7a4a932fe4c38463389f8119d0c9e48523c38800c1ce9d59f63aaaa04bb4ecd593530bb234b9862029e4ec2fe
7
+ data.tar.gz: 84843f80e10c3391e9f0f7734217745d88890cc4f8d222a045aa2440124a8509c3a8b1b87776a2558b98c1b4ddf3510b30353450e9335608062dd9e6e7ef980c
data/History.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog for chef-gen-flavors
2
2
 
3
+ ## 0.8.0
4
+
5
+ * give snippets the ability to use the add_render to construct resources with additional attributes
6
+ * add local override inclusion for Gemfile, Berksfile and Guardfile to snippets
7
+ * allow the CookbookBase snippet's @cookbook_gems hash to take an String or Array value. A string is a constraint, an Array is a constraint plus 0..n extra args (like a git source)
8
+
3
9
  ## 0.7.0
4
10
 
5
11
  Major re-organization around snippets
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: chef-gen-flavors 0.7.0.20150609141116 ruby lib
2
+ # stub: chef-gen-flavors 0.8.0.20150618104356 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "chef-gen-flavors"
6
- s.version = "0.7.0.20150609141116"
6
+ s.version = "0.8.0.20150618104356"
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-09"
11
+ s.date = "2015-06-18"
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
14
  s.extra_rdoc_files = ["ARUBA_STEPS.md", "History.md", "Manifest.txt", "README.md"]
@@ -171,11 +171,13 @@ module ChefGen
171
171
  # @return [void]
172
172
  # @api private
173
173
  def add_files
174
- _add_files(
175
- @files, nil, @fail_on_clobber, :cookbook_file, :create
174
+ add_render(
175
+ @files,
176
+ suffix: '', resource: :cookbook_file, resource_action: :create
176
177
  )
177
- _add_files(
178
- @files_if_missing, nil, false, :cookbook_file, :create_if_missing
178
+ add_render(
179
+ @files_if_missing,
180
+ suffix: '', clobberfail: false, resource: :cookbook_file
179
181
  )
180
182
  end
181
183
 
@@ -184,43 +186,55 @@ module ChefGen
184
186
  # @return [void]
185
187
  # @api private
186
188
  def add_templates
187
- _add_files(
188
- @templates, '.erb', @fail_on_clobber, :template, :create
189
- )
190
- _add_files(
191
- @templates_if_missing, '.erb', false, :template, :create_if_missing
192
- )
189
+ add_render(@templates, resource_action: :create)
190
+ add_render(@templates_if_missing, clobberfail: false)
193
191
  end
194
192
 
195
193
  # does the heavy lifting for add_files and add_templates
196
- # @param files [Array] the list of things to declare
194
+ # @param things [Array] the list of things to declare
197
195
  # @param suffix [String] a suffix to add to the source file
198
196
  # @param clobberfail [Boolean] whether to protect against
199
197
  # overwriting files
200
198
  # @param resource [Symbol] the symbolized Chef resource to declare
201
199
  # @param resource_action [Symbol] the action to give the resource
200
+ # @param attrs [Hash] additional attributes to send to the resource.
201
+ # Keys are methods, values are parameters
202
202
  # @return [void]
203
203
  # @api private
204
- def _add_files(files, suffix, clobberfail, resource, resource_action)
205
- files.flatten.each do |filename|
204
+ def add_render( # rubocop:disable Metrics/ParameterLists
205
+ things,
206
+ suffix: '.erb', clobberfail: @fail_on_clobber,
207
+ resource: :template, resource_action: :create_if_missing,
208
+ attrs: {}
209
+ )
210
+ things.flatten.each do |filename|
206
211
  src = "#{source_path(filename)}#{suffix}"
207
212
  dst = File.join(@target_path, filename)
208
213
  if clobberfail && File.exist?(dst)
209
214
  @failures << "tried to overwrite file #{dst}"
210
215
  else
211
- @recipe.send(resource, dst) do
212
- # :nocov:
213
- source src
214
- action resource_action
215
- helpers(ChefDK::Generator::TemplateHelper) \
216
- if :template == resource
217
- # :nocov:
218
- end
219
- @actions_taken << "create file #{dst}"
216
+ _add_resource(resource, src, dst, resource_action, attrs)
220
217
  end
221
218
  end
222
219
  end
223
220
 
221
+ # adds a resource to the recipe
222
+ # @api private
223
+ def _add_resource(type, src, dst, action, attrs)
224
+ @recipe.send(type, dst) do
225
+ # :nocov:
226
+ source src
227
+ action action
228
+ helpers(ChefDK::Generator::TemplateHelper) \
229
+ if :template == type
230
+ attrs.each do |attr, value|
231
+ send attr, value
232
+ end
233
+ # :nocov:
234
+ end
235
+ @actions_taken << "add resource #{type}[#{dst}]"
236
+ end
237
+
224
238
  # reports on the actions taken by the plugin
225
239
  # @param actions [Array] the list of actions taken
226
240
  # @return [void]
@@ -8,7 +8,7 @@ module ChefGen
8
8
  # a plugin framework for creating ChefDK generator flavors
9
9
  class Flavors
10
10
  # the version of the gem
11
- VERSION = '0.7.0'
11
+ VERSION = '0.8.0'
12
12
 
13
13
  extend LittlePlugger path: 'chef_gen/flavor',
14
14
  module: ChefGen::Flavor
@@ -1,4 +1,3 @@
1
1
  Given(/^I list the kitchen suites$/) do
2
- unset_bundler_env_vars
3
2
  run_simple 'bundle exec kitchen list'
4
3
  end
@@ -1,14 +1,11 @@
1
1
  Given(/^I run a style test$/) do
2
- unset_bundler_env_vars
3
- run_simple 'bundle exec rake style', true, 10
2
+ run_simple 'bundle exec rake style', true, @aruba_timeout_seconds
4
3
  end
5
4
 
6
5
  Given(/^I run a unit test$/) do
7
- unset_bundler_env_vars
8
- run_simple 'bundle exec rake spec', true, 10
6
+ run_simple 'bundle exec rake spec', true, @aruba_timeout_seconds
9
7
  end
10
8
 
11
9
  Given(/^I list the rake tasks$/) do
12
- unset_bundler_env_vars
13
10
  run_simple 'bundle exec rake -T'
14
11
  end
@@ -1,5 +1,7 @@
1
1
  # rubocop:disable Metrics/MethodLength
2
2
 
3
+ require 'chef/mixin/params_validate'
4
+
3
5
  module ChefGen
4
6
  module Snippet
5
7
  # creates the basic files that every cookbook should have
@@ -28,13 +30,13 @@ module ChefGen
28
30
  @rake_tasks = {}
29
31
  @guard_sets = {}
30
32
  @cookbook_gems = {
31
- rake: '~> 10.4',
32
- pry: '~> 0.10',
33
+ 'rake' => '~> 10.4',
34
+ 'pry' => '~> 0.10',
33
35
  'pry-byebug' => '~> 3.1',
34
36
  'pry-rescue' => '~> 1.4',
35
37
  'pry-stack_explorer' => '~> 0.4',
36
- berkshelf: '~> 3.2',
37
- guard: '~> 2.12'
38
+ 'berkshelf' => '~> 3.2',
39
+ 'guard' => '~> 2.12'
38
40
  }
39
41
  end
40
42
 
@@ -55,12 +57,16 @@ module ChefGen
55
57
  def snippet_cookbookbase_gemfile(recipe)
56
58
  gems = @cookbook_gems
57
59
  sources = @gem_sources
58
- # :nocov:
59
- recipe.send(:template, File.join(@target_path, 'Gemfile')) do
60
- helpers(ChefDK::Generator::TemplateHelper)
61
- variables lazy { { gems: gems, sources: sources } }
60
+ lazy_vars = Chef::DelayedEvaluator.new do
61
+ { gems: gems, sources: sources }
62
62
  end
63
63
  # :nocov:
64
+ add_render(
65
+ %w(Gemfile),
66
+ resource_action: :create,
67
+ attrs: { variables: lazy_vars }
68
+ )
69
+ # :nocov:
64
70
  end
65
71
 
66
72
  # declares the Berksfile with lazy evaluation of the sources
@@ -69,12 +75,16 @@ module ChefGen
69
75
  # @return [void]
70
76
  def snippet_cookbookbase_berksfile(recipe)
71
77
  sources = @berks_sources
72
- # :nocov:
73
- recipe.send(:template, File.join(@target_path, 'Berksfile')) do
74
- helpers(ChefDK::Generator::TemplateHelper)
75
- variables lazy { { sources: sources } }
78
+ lazy_vars = Chef::DelayedEvaluator.new do
79
+ { sources: sources }
76
80
  end
77
81
  # :nocov:
82
+ add_render(
83
+ %w(Berksfile),
84
+ resource_action: :create,
85
+ attrs: { variables: lazy_vars }
86
+ )
87
+ # :nocov:
78
88
  end
79
89
 
80
90
  # declares the Rakefile with lazy evaluation of the tasks
@@ -83,12 +93,16 @@ module ChefGen
83
93
  # @return [void]
84
94
  def snippet_cookbookbase_rakefile(recipe)
85
95
  tasks = @rake_tasks
86
- # :nocov:
87
- recipe.send(:template, File.join(@target_path, 'Rakefile')) do
88
- helpers(ChefDK::Generator::TemplateHelper)
89
- variables lazy { { tasks: tasks } }
96
+ lazy_vars = Chef::DelayedEvaluator.new do
97
+ { tasks: tasks }
90
98
  end
91
99
  # :nocov:
100
+ add_render(
101
+ %w(Rakefile),
102
+ resource_action: :create,
103
+ attrs: { variables: lazy_vars }
104
+ )
105
+ # :nocov:
92
106
  end
93
107
 
94
108
  # declares the Guardfile with lazy evaluation of the guards
@@ -97,12 +111,16 @@ module ChefGen
97
111
  # @return [void]
98
112
  def snippet_cookbookbase_guardfile(recipe)
99
113
  guards = @guard_sets
100
- # :nocov:
101
- recipe.send(:template, File.join(@target_path, 'Guardfile')) do
102
- helpers(ChefDK::Generator::TemplateHelper)
103
- variables lazy { { guards: guards } }
114
+ lazy_vars = Chef::DelayedEvaluator.new do
115
+ { guards: guards }
104
116
  end
105
117
  # :nocov:
118
+ add_render(
119
+ %w(Guardfile),
120
+ resource_action: :create,
121
+ attrs: { variables: lazy_vars }
122
+ )
123
+ # :nocov:
106
124
  end
107
125
 
108
126
  # adds base files to the git and chefignore patterns
@@ -112,10 +130,7 @@ module ChefGen
112
130
  def snippet_cookbookbase_ignore(recipe)
113
131
  return unless respond_to?(:chefignore_patterns)
114
132
  %w(
115
- Gemfile
116
- Rakefile
117
- Guardfile
118
- Berksfile
133
+ Gemfile Rakefile Guardfile Berksfile
119
134
  ).each do |e|
120
135
  chefignore_patterns << e
121
136
  end
@@ -126,13 +141,8 @@ module ChefGen
126
141
  # @return [void]
127
142
  def content_cookbookbase_files(path)
128
143
  %w(
129
- Gemfile.erb
130
- Berksfile.erb
131
- Rakefile.erb
132
- Guardfile.erb
133
- metadata_rb.erb
134
- README_md.erb
135
- CHANGELOG_md.erb
144
+ Gemfile.erb Berksfile.erb Rakefile.erb Guardfile.erb
145
+ metadata_rb.erb README_md.erb CHANGELOG_md.erb
136
146
  ).each do |file|
137
147
  # :nocov:
138
148
  copy_snippet_file(
@@ -3,3 +3,10 @@ source '<%= source %>'
3
3
  <% end -%>
4
4
 
5
5
  metadata
6
+
7
+ # load local overrides
8
+ berksfile_dir = File.absolute_path(File.join('.', 'lib', 'berksfile'))
9
+ Dir.glob(File.join(berksfile_dir, '*.berks')).each do |snippet|
10
+ # rubocop:disable Lint/Eval
11
+ eval File.read(snippet), nil, snippet
12
+ end
@@ -2,6 +2,18 @@
2
2
  source '<%= source %>'
3
3
  <% end -%>
4
4
 
5
- <% @gems.each do |gem, constraint| -%>
6
- gem '<%= gem %>', '<%= constraint %>'
5
+ # rubocop:disable Metrics/LineLength
6
+ <% @gems.each do |gem, config| -%>
7
+ <% if config.is_a?(Array) -%>
8
+ gem '<%= gem %>', '<%= config[0] %>', <%= config[1..-1].join(', ') %>
9
+ <% else -%>
10
+ gem '<%= gem %>', '<%= config %>'
7
11
  <% end -%>
12
+ <% end -%>
13
+
14
+ # load local overrides
15
+ gemfile_dir = File.absolute_path(File.join('.', 'lib', 'gemfile'))
16
+ Dir.glob(File.join(gemfile_dir, '*.bundler')).each do |snippet|
17
+ # rubocop:disable Lint/Eval
18
+ eval File.read(snippet), nil, snippet
19
+ end
@@ -8,3 +8,9 @@ interactor :off
8
8
  <%= guard %>
9
9
 
10
10
  <% end -%>
11
+
12
+ # load local overrides
13
+ guardfile_dir = File.absolute_path(File.join('.', 'lib', 'guardfile'))
14
+ Dir.glob(File.join(guardfile_dir, '*.guard')).each do |snippet|
15
+ eval File.read(snippet), nil, snippet # rubocop:disable Lint/Eval
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-gen-flavors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James FitzGibbon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: little-plugger