chef-gen-flavors 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +5 -1
- data/README.md +21 -0
- data/lib/chef_gen/flavors.rb +25 -4
- data/spec/lib/chef_gen/flavors_spec.rb +19 -3
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: add24d646e518bc09136c0a9408a401b5cf2061b
|
|
4
|
+
data.tar.gz: a18a07d894bc08162243b83a3eeffb10721459dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 057890d70675eaff78246d63fe20c1e4a3f90407da51c763676a61e42c758068c662eae72c0d5563914a1732609b0bb7e42968435298a5b2d730547d3e8cf48e
|
|
7
|
+
data.tar.gz: b5b3e8661789f468ec57a5c9ba91da998a34bee40be504c5a504625d3ac94a538945ffdd0cc93c5cb371ded68d5559c0f0b5cebb6fe41ab0ce739a5c219c4954
|
data/History.md
CHANGED
data/README.md
CHANGED
|
@@ -115,6 +115,12 @@ The directory structure of a plugin looks like this:
|
|
|
115
115
|
└── flavor
|
|
116
116
|
└── example.rb
|
|
117
117
|
|
|
118
|
+
It is important that the name of the directory in which your generator
|
|
119
|
+
cookbook lives matches the name in metadata.rb. ChefDK uses the last
|
|
120
|
+
element of the path as the cookbook name, so if you put your cookbook
|
|
121
|
+
in a folder called 'cookbook' but your metadata.rb declares the name
|
|
122
|
+
as 'code_generator', ChefDK won't be able to find your recipe.
|
|
123
|
+
|
|
118
124
|
## ALTERNATE code_generator PATHS
|
|
119
125
|
|
|
120
126
|
By default, the code_generator cookbook is assumed to live in a directory
|
|
@@ -154,6 +160,21 @@ For compatibility with all platforms supported by ChefDK, plugins should use
|
|
|
154
160
|
the methods in the `File` class to construct relative paths rather than
|
|
155
161
|
assuming what the path separator should be.
|
|
156
162
|
|
|
163
|
+
## GENERATOR PATH COPY
|
|
164
|
+
|
|
165
|
+
When #path is called, chef-gen-flavors makes a copy of the selected
|
|
166
|
+
generator cookbook to a temporary path, which is what gets returned
|
|
167
|
+
and used by ChefDK. This path is cleaned up at exit unless the environment
|
|
168
|
+
variable CHEFGEN_NOCLEANTMP is set.
|
|
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
|
|
172
|
+
|
|
173
|
+
ChefDK::Generator.context.generator_path
|
|
174
|
+
|
|
175
|
+
This is foundational work to allow snippets to include content as well
|
|
176
|
+
as declarations of what files they will render.
|
|
177
|
+
|
|
157
178
|
## FLAVOR BASE CLASS
|
|
158
179
|
|
|
159
180
|
Inside of your plugin's code_generator cookbook, you can do anything that
|
data/lib/chef_gen/flavors.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
1
2
|
require 'little-plugger'
|
|
2
3
|
|
|
3
4
|
require 'chef_gen/flavor'
|
|
@@ -7,14 +8,14 @@ module ChefGen
|
|
|
7
8
|
# a plugin framework for creating ChefDK generator flavors
|
|
8
9
|
class Flavors
|
|
9
10
|
# the version of the gem
|
|
10
|
-
VERSION = '0.
|
|
11
|
+
VERSION = '0.6.0'
|
|
11
12
|
|
|
12
13
|
extend LittlePlugger path: 'chef_gen/flavor',
|
|
13
14
|
module: ChefGen::Flavor
|
|
14
15
|
|
|
15
16
|
class << self
|
|
16
|
-
# return the path to to the
|
|
17
|
-
# the selected ChefGen Flavor
|
|
17
|
+
# return the path to to the copy of the generator cookbook
|
|
18
|
+
# for the selected ChefGen Flavor
|
|
18
19
|
# @return [String] the path to the code_generator cookbook
|
|
19
20
|
def path
|
|
20
21
|
# then take a copy so we can augment it
|
|
@@ -26,7 +27,10 @@ module ChefGen
|
|
|
26
27
|
fail('no ChefGen flavors found!')
|
|
27
28
|
path = generator_path(selected)
|
|
28
29
|
$stdout.puts "using ChefGen flavor '#{selected}' in #{path}"
|
|
29
|
-
path
|
|
30
|
+
copy = copy_generator_dir(path, selected)
|
|
31
|
+
ChefDK::Generator.add_attr_to_context('generator_path', copy)
|
|
32
|
+
$stdout.puts "using copy of generator in #{copy}"
|
|
33
|
+
copy
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
private
|
|
@@ -156,6 +160,23 @@ module ChefGen
|
|
|
156
160
|
spec.gem_dir, 'lib', 'chef-dk', 'skeletons', 'code_generator'
|
|
157
161
|
)
|
|
158
162
|
end
|
|
163
|
+
|
|
164
|
+
# recursively copies the generator cookbook to a temporary
|
|
165
|
+
# directory. Sets up an at_exit handler to remove the
|
|
166
|
+
# temporary directory unless CHEFGEN_NOCLEANTMP is set
|
|
167
|
+
# in the environment.
|
|
168
|
+
# @param srcdir [String] the path to the generator cookbook
|
|
169
|
+
# @return [String] the temporary path to generate from
|
|
170
|
+
def copy_generator_dir(srcdir, selected)
|
|
171
|
+
dstdir = Dir.mktmpdir('chefgen_flavor.')
|
|
172
|
+
at_exit {
|
|
173
|
+
$stdout.puts "cleaning up generator copy in ${dstdir}"
|
|
174
|
+
FileUtils.rm_rf(dstdir)
|
|
175
|
+
} unless ENV.key?('CHEFGEN_NOCLEANTMP')
|
|
176
|
+
$stdout.puts "copying #{srcdir} to #{dstdir}"
|
|
177
|
+
FileUtils.cp_r(srcdir, dstdir)
|
|
178
|
+
File.join(dstdir, File.basename(srcdir))
|
|
179
|
+
end
|
|
159
180
|
end
|
|
160
181
|
end
|
|
161
182
|
end
|
|
@@ -103,14 +103,30 @@ RSpec.describe ChefGen::Flavors do
|
|
|
103
103
|
it 'should default the code_generator path' do
|
|
104
104
|
ChefGen::Flavors.disregard_plugin :baz
|
|
105
105
|
ENV['CHEFGEN_FLAVOR'] = 'Foo'
|
|
106
|
-
expect(
|
|
107
|
-
|
|
106
|
+
expect(FileUtils).to receive(:cp_r).with(
|
|
107
|
+
%r{spec/support/fixtures/code_generator$}, String
|
|
108
|
+
)
|
|
109
|
+
ChefGen::Flavors.path
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
it 'should respect an overridden code_generator path' do
|
|
111
113
|
ChefGen::Flavors.disregard_plugin :baz
|
|
112
114
|
ENV['CHEFGEN_FLAVOR'] = 'Bar'
|
|
115
|
+
expect(FileUtils).to receive(:cp_r).with(
|
|
116
|
+
%r{spec/support/fixtures/code_generator_2$}, String
|
|
117
|
+
)
|
|
118
|
+
ChefGen::Flavors.path
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'should copy the code_generator to a temp directory' do
|
|
122
|
+
ChefGen::Flavors.disregard_plugin :baz
|
|
123
|
+
ENV['CHEFGEN_FLAVOR'] = 'Foo'
|
|
124
|
+
tmpdir = Dir.tmpdir
|
|
125
|
+
expect(FileUtils).to receive(:cp_r).with(
|
|
126
|
+
%r{spec/support/fixtures/code_generator$},
|
|
127
|
+
%r{#{tmpdir}/chefgen_flavor\..+$}
|
|
128
|
+
)
|
|
113
129
|
expect(ChefGen::Flavors.path)
|
|
114
|
-
.to match(%r{
|
|
130
|
+
.to match(%r{#{tmpdir}/chefgen_flavor\..+$})
|
|
115
131
|
end
|
|
116
132
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -49,6 +49,7 @@ module ChefDKGeneratorContext
|
|
|
49
49
|
allow(@ctx).to receive(:cookbook_name).and_return('foo')
|
|
50
50
|
allow(@ctx).to receive(:have_git).and_return(true)
|
|
51
51
|
allow(@ctx).to receive(:skip_git_init).and_return(false)
|
|
52
|
+
allow(@ctx).to receive(:generator_path=)
|
|
52
53
|
allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
|
|
53
54
|
end
|
|
54
55
|
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.
|
|
4
|
+
version: 0.6.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-05
|
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: little-plugger
|