chef-cookie_cutter 0.1.0 → 0.2.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/lib/chef/cookie_cutter.rb +11 -23
- data/lib/chef/cookie_cutter/extended_provides.rb +19 -10
- data/lib/chef/cookie_cutter/fake_resource.rb +38 -0
- data/lib/chef/cookie_cutter/fancy_property.rb +41 -0
- data/lib/chef/cookie_cutter/lwrp_build_params.rb +39 -30
- data/lib/chef/cookie_cutter/lwrp_include.rb +107 -16
- data/lib/chef/cookie_cutter/namespace.rb +49 -44
- data/lib/chef/cookie_cutter/run_state.rb +20 -14
- data/lib/chef/cookie_cutter/shared_blocks.rb +19 -13
- data/lib/chef/cookie_cutter/spec_matchers.rb +54 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4db0c57ad4430870c0c6bdf8c3c522ffd14787c
|
4
|
+
data.tar.gz: fa7dd0a9ce574447b8da18c156344f3ca1c32794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d41c1d0325d21a8dd7daa6fede520be658718ba2a48b69b13edfa063bda69d7578b4605e42fd48270335352ed6e64594b8a3f8c9ca4895843148ad7102d0c42
|
7
|
+
data.tar.gz: ab1b3e57a68edb7845ae5a92818f59187d3776f7b5b31bc8b40b57a11778a9803474ebe0a755b340000684f430a4834e18b5dc032e3af7a8cc427cc8fee502cb
|
data/lib/chef/cookie_cutter.rb
CHANGED
@@ -22,35 +22,23 @@ require 'chef/provider/lwrp_base'
|
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
module CookieCutter
|
25
|
-
def self.chef_version(constraint)
|
26
|
-
gem_version = ::Gem::Version.new(::Chef::VERSION)
|
27
|
-
::Gem::Requirement.new(constraint).satisfied_by?(gem_version)
|
28
|
-
end
|
29
|
-
|
30
|
-
require_relative 'cookie_cutter/fancy_property' if chef_version('~> 12.5')
|
31
|
-
|
32
25
|
require_relative 'cookie_cutter/extended_provides'
|
26
|
+
require_relative 'cookie_cutter/fake_resource'
|
27
|
+
require_relative 'cookie_cutter/fancy_property'
|
33
28
|
require_relative 'cookie_cutter/lwrp_build_params'
|
34
29
|
require_relative 'cookie_cutter/lwrp_include'
|
35
30
|
require_relative 'cookie_cutter/namespace'
|
36
31
|
require_relative 'cookie_cutter/run_state'
|
37
32
|
require_relative 'cookie_cutter/shared_blocks'
|
33
|
+
require_relative 'cookie_cutter/spec_matchers'
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Chef::
|
45
|
-
Chef::
|
46
|
-
Chef::
|
47
|
-
Chef::
|
48
|
-
Chef::
|
49
|
-
|
50
|
-
# Register DSL
|
51
|
-
Chef::Recipe.send :include, CC::DSL
|
52
|
-
Chef::Resource.send :include, CC::DSL
|
53
|
-
Chef::Provider.send :include, CC::DSL
|
54
|
-
Chef::Node.send :include, CC::AttributeDSL
|
55
|
-
Chef::Resource::LWRPBase.send :extend, CC::ResourceDSL
|
56
|
-
Chef::Provider::LWRPBase.send :extend, CC::ProviderDSL
|
37
|
+
Chef::CookieCutter::ExtendedProvides.register
|
38
|
+
Chef::CookieCutter::FancyPropertyModule.register
|
39
|
+
Chef::CookieCutter::LWRPBuildParams.register
|
40
|
+
Chef::CookieCutter::LWRPInclude.register
|
41
|
+
Chef::CookieCutter::Namespace.register
|
42
|
+
Chef::CookieCutter::RunState.register
|
43
|
+
Chef::CookieCutter::SharedBlocks.register
|
44
|
+
Chef::CookieCutter::SpecMatchers.register
|
@@ -17,19 +17,28 @@
|
|
17
17
|
|
18
18
|
class Chef
|
19
19
|
module CookieCutter
|
20
|
-
module
|
21
|
-
|
22
|
-
attr_reader :resource_builder
|
20
|
+
module ExtendedProvides
|
21
|
+
module_function
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def register
|
24
|
+
Chef::RunContext.send :prepend, MonkeyPatches::RunContext
|
25
|
+
Chef::ResourceBuilder.send :prepend, MonkeyPatches::ResourceBuilder
|
27
26
|
end
|
28
27
|
|
29
|
-
module
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
module MonkeyPatches
|
29
|
+
module RunContext
|
30
|
+
attr_reader :resource_builder
|
31
|
+
|
32
|
+
def build_resource(builder)
|
33
|
+
@resource_builder = builder
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module ResourceBuilder
|
38
|
+
def build(&block)
|
39
|
+
run_context.build_resource(self)
|
40
|
+
super(&block)
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2015, Ole Claussen <claussen.ole@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
class Chef
|
19
|
+
module CookieCutter
|
20
|
+
module FakeResource
|
21
|
+
class FakeClass
|
22
|
+
extend FakeResource
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(*)
|
26
|
+
# do nothing
|
27
|
+
end
|
28
|
+
|
29
|
+
def respond_to?(*)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def const_missing(*)
|
34
|
+
FakeClass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -17,7 +17,48 @@
|
|
17
17
|
require 'chef/property'
|
18
18
|
|
19
19
|
class Chef
|
20
|
+
# Define Chef::Property in case we are pre 12.5 and it doesn't exist yet.
|
21
|
+
class Property
|
22
|
+
end
|
23
|
+
|
20
24
|
module CookieCutter
|
25
|
+
module FancyPropertyModule
|
26
|
+
module_function
|
27
|
+
|
28
|
+
# rubocop:disable Style/GuardClause
|
29
|
+
def register
|
30
|
+
if defined?(DocumentingLWRPBase)
|
31
|
+
DocumentingLWRPBase.send :extend, DocumentingResourceDSL
|
32
|
+
end
|
33
|
+
if defined?(KnifeCookbookDoc)
|
34
|
+
KnifeCookbookDoc::ResourceModel.send :prepend, MonkeyPatches::DocumentResourceModel
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module DocumentingResourceDSL
|
39
|
+
def property(name, type = NOT_PASSED, **options)
|
40
|
+
result = super(name, type, options)
|
41
|
+
attribute_specifications[name] = options
|
42
|
+
result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module MonkeyPatches
|
47
|
+
# Monkey Patches for KnifeCookbookDoc::ResourceModel
|
48
|
+
# Enriches attribute/property description with additional info
|
49
|
+
# if certain options are passed to FancyProperty
|
50
|
+
module DocumentResourceModel
|
51
|
+
def attribute_description(attribute)
|
52
|
+
description = super || ''
|
53
|
+
opts = @native_resource.attribute_specifications[attribute]
|
54
|
+
description += " Must be a `#{opts[:coerce_resource]}` resource or a block." if opts.key?(:coerce_resource)
|
55
|
+
description += ' This attribute can be specified multiple times.' if opts.key?(:collect)
|
56
|
+
description
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
21
62
|
class FancyProperty < ::Chef::Property
|
22
63
|
def call(resource, *args, **kwargs, &blk)
|
23
64
|
return get(resource) if args.empty? && kwargs.empty? && !block_given?
|
@@ -17,43 +17,52 @@
|
|
17
17
|
|
18
18
|
class Chef
|
19
19
|
module CookieCutter
|
20
|
-
module
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
module LWRPBuildParams
|
21
|
+
module_function
|
22
|
+
|
23
|
+
def register
|
24
|
+
Chef::Resource::LWRPBase.send :prepend, MonkeyPatches::LWRPResource
|
25
|
+
Chef::Provider::LWRPBase.send :prepend, MonkeyPatches::LWRPProvider
|
26
|
+
end
|
27
|
+
|
28
|
+
module MonkeyPatches
|
29
|
+
# Monkey Patches for Chef::Resource::LWRPBase
|
30
|
+
# Makes the parameters of build_from_file (i.e. cookbook_name, filename
|
31
|
+
# and run_context) available in the created class.
|
32
|
+
module LWRPResource
|
33
|
+
module ClassMethods
|
34
|
+
def build_from_file(cookbook_name, filename, run_context)
|
35
|
+
define_singleton_method(:lwrp_cookbook_name) { cookbook_name }
|
36
|
+
define_singleton_method(:lwrp_filename) { filename }
|
37
|
+
define_singleton_method(:lwrp_run_context) { run_context }
|
38
|
+
super
|
39
|
+
end
|
31
40
|
end
|
32
|
-
end
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
def self.prepended(base)
|
43
|
+
class << base
|
44
|
+
prepend ClassMethods
|
45
|
+
end
|
37
46
|
end
|
38
47
|
end
|
39
|
-
end
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
# Monkey Patches for Chef::Provider::LWRPBase
|
50
|
+
# Makes the parameters of build_from_file (i.e. cookbook_name, filename
|
51
|
+
# and run_context) available in the created class.
|
52
|
+
module LWRPProvider
|
53
|
+
module ClassMethods
|
54
|
+
def build_from_file(cookbook_name, filename, run_context)
|
55
|
+
define_singleton_method(:lwrp_cookbook_name) { cookbook_name }
|
56
|
+
define_singleton_method(:lwrp_filename) { filename }
|
57
|
+
define_singleton_method(:lwrp_run_context) { run_context }
|
58
|
+
super
|
59
|
+
end
|
51
60
|
end
|
52
|
-
end
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
62
|
+
def self.prepended(base)
|
63
|
+
class << base
|
64
|
+
prepend ClassMethods
|
65
|
+
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
@@ -20,6 +20,20 @@ class Chef
|
|
20
20
|
module LWRPInclude
|
21
21
|
module_function
|
22
22
|
|
23
|
+
# rubocop:disable Style/GuardClause
|
24
|
+
def register
|
25
|
+
Chef::Resource::LWRPBase.send :extend, ResourceDSL
|
26
|
+
Chef::Provider::LWRPBase.send :extend, ProviderDSL
|
27
|
+
if defined?(DocumentingLWRPBase)
|
28
|
+
DocumentingLWRPBase.send :extend, DocumentingResourceDSL
|
29
|
+
DocumentingLWRPBase.send :extend, FakeResource
|
30
|
+
end
|
31
|
+
if defined?(KnifeCookbookDoc)
|
32
|
+
KnifeCookbookDoc::ReadmeModel.send :prepend, MonkeyPatches::DocumentReadmeModel
|
33
|
+
KnifeCookbookDoc::ResourceModel.send :prepend, MonkeyPatches::DocumentResourceModel
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
23
37
|
def try_file(filename)
|
24
38
|
return if File.exist?(filename) && File.readable?(filename)
|
25
39
|
fail IOError, "Cannot open or read #{filename}"
|
@@ -42,25 +56,102 @@ class Chef
|
|
42
56
|
end
|
43
57
|
resource_module
|
44
58
|
end
|
45
|
-
end
|
46
59
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
60
|
+
module ResourceDSL
|
61
|
+
def lwrp_include(name, cookbook: nil)
|
62
|
+
cookbook = lwrp_cookbook_name if cookbook.nil?
|
63
|
+
context = lwrp_run_context
|
64
|
+
filename = LWRPInclude.filename_for_record(context, cookbook, :resources, name)
|
65
|
+
include LWRPInclude.build_resource_module_from_file(filename)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module ProviderDSL
|
70
|
+
def lwrp_include(name, cookbook: nil)
|
71
|
+
cookbook = lwrp_cookbook_name if cookbook.nil?
|
72
|
+
context = lwrp_run_context
|
73
|
+
filename = LWRPInclude.filename_for_record(context, cookbook, :providers, name)
|
74
|
+
include LWRPInclude.build_resource_module_from_file(filename)
|
75
|
+
end
|
54
76
|
end
|
55
|
-
end
|
56
77
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
78
|
+
module DocumentingResourceDSL
|
79
|
+
def mixins
|
80
|
+
@mixins ||= []
|
81
|
+
end
|
82
|
+
|
83
|
+
def lwrp_include(name, cookbook: nil)
|
84
|
+
mixins << { name: name, cookbook: cookbook }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module MonkeyPatches
|
89
|
+
# Monkey Patches for KnifeCookbookDoc::ReadmeModel
|
90
|
+
# Additionally searches for resource files in sub directories in addition.
|
91
|
+
# Adds getter for mixin resources.
|
92
|
+
module DocumentReadmeModel
|
93
|
+
def initialize(cookbook_dir, constraints)
|
94
|
+
super
|
95
|
+
Dir["#{cookbook_dir}/resources/*/**/*.rb"].sort.each do |resource_filename|
|
96
|
+
@resources << ::KnifeCookbookDoc::ResourceModel.new(@metadata.name, resource_filename)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def resources
|
101
|
+
@resources.reject(&:mixin?)
|
102
|
+
end
|
103
|
+
|
104
|
+
def mixin_resources
|
105
|
+
@resources.select(&:mixin?)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Monkey Patches for KnifeCookbookDoc::ResourceModel
|
110
|
+
# Overwrites load_descriptions to additionally check if a lwrp is a mixin.
|
111
|
+
# Saves cookbook and file name in instance variables
|
112
|
+
module DocumentResourceModel
|
113
|
+
def initialize(cookbook_name, file)
|
114
|
+
@cookbook_name = cookbook_name
|
115
|
+
@file = file
|
116
|
+
super
|
117
|
+
end
|
118
|
+
|
119
|
+
def name
|
120
|
+
return filename_to_qualified_string(@cookbook_name, @file) if mixin?
|
121
|
+
super
|
122
|
+
end
|
123
|
+
|
124
|
+
def mixin?
|
125
|
+
@mixin
|
126
|
+
end
|
127
|
+
|
128
|
+
def mixins
|
129
|
+
@native_resource.mixins.map do |mixin|
|
130
|
+
mixin[:cookbook] = @cookbook_name if mixin[:cookbook].nil?
|
131
|
+
filename_to_qualified_string(mixin[:cookbook], mixin[:name])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# rubocop:disable Style/PerlBackrefs
|
136
|
+
def load_descriptions
|
137
|
+
current_section = 'main'
|
138
|
+
@native_resource.description.each_line do |line|
|
139
|
+
if /^ *\@action *([^ ]*) (.*)$/ =~ line
|
140
|
+
action_descriptions[$1] = $2.strip
|
141
|
+
elsif /^ *\@attribute *([^ ]*) (.*)$/ =~ line
|
142
|
+
attribute_descriptions[$1] = $2.strip
|
143
|
+
elsif /^ *\@section (.*)$/ =~ line
|
144
|
+
current_section = $1.strip
|
145
|
+
elsif /^ *\@mixin(.*)$/ =~ line
|
146
|
+
@mixin = true
|
147
|
+
else
|
148
|
+
lines = (top_level_descriptions[current_section] || [])
|
149
|
+
lines << line.delete("\n")
|
150
|
+
top_level_descriptions[current_section] = lines
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
64
155
|
end
|
65
156
|
end
|
66
157
|
end
|
@@ -20,6 +20,13 @@ class Chef
|
|
20
20
|
module Namespace
|
21
21
|
module_function
|
22
22
|
|
23
|
+
def register
|
24
|
+
Chef::Recipe.send :include, DSL
|
25
|
+
Chef::Resource.send :include, DSL
|
26
|
+
Chef::Provider.send :include, DSL
|
27
|
+
Chef::Node.send :prepend, MonkeyPatches::Node
|
28
|
+
end
|
29
|
+
|
23
30
|
class AttributeDoesNotExistError < StandardError
|
24
31
|
def initialize(keys, key)
|
25
32
|
super <<-EOH
|
@@ -37,61 +44,59 @@ EOH
|
|
37
44
|
if hash.key?(key)
|
38
45
|
hash[key]
|
39
46
|
else
|
40
|
-
fail
|
47
|
+
fail AttributeDoesNotExistError.new(keys, key)
|
41
48
|
end
|
42
49
|
end
|
43
50
|
end
|
44
|
-
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@current_namespace = current_namespace - keys
|
53
|
-
@namespace_options = nil if @current_namespace.empty?
|
54
|
-
nil
|
52
|
+
module DSL
|
53
|
+
def namespace(*args)
|
54
|
+
keys = args.map(&:to_s)
|
55
|
+
attribute = Namespace.deep_fetch(node.attributes, keys)
|
56
|
+
yield attribute if block_given?
|
57
|
+
end
|
55
58
|
end
|
56
59
|
|
57
|
-
|
60
|
+
module MonkeyPatches
|
61
|
+
module Node
|
62
|
+
def namespace(*args, **kwargs, &blk)
|
63
|
+
@namespace_options = namespace_options.merge(kwargs)
|
64
|
+
keys = args.map(&:to_s)
|
65
|
+
@current_namespace = current_namespace + keys
|
66
|
+
instance_eval(&blk) if block_given?
|
67
|
+
@current_namespace = current_namespace - keys
|
68
|
+
@namespace_options = nil if @current_namespace.empty?
|
69
|
+
nil
|
70
|
+
end
|
58
71
|
|
59
|
-
|
60
|
-
|
61
|
-
|
72
|
+
def method_missing(method_name, *args)
|
73
|
+
super
|
74
|
+
rescue NoMethodError
|
75
|
+
if args.empty?
|
76
|
+
deep_key = current_namespace.dup << method_name.to_s
|
77
|
+
return Namespace.deep_fetch!(attributes, deep_key)
|
78
|
+
else
|
79
|
+
vivified[method_name.to_s] = args.size == 1 ? args.first : args
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
end
|
62
83
|
|
63
|
-
|
64
|
-
@current_namespace ||= []
|
65
|
-
end
|
84
|
+
private
|
66
85
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
hash[item] ||= {}
|
71
|
-
hash[item]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
86
|
+
def namespace_options
|
87
|
+
@namespace_options ||= { precedence: default }
|
88
|
+
end
|
75
89
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
attribute = ::Chef::CookieCutter::Namespace.deep_fetch(node.attributes, keys)
|
80
|
-
yield attribute if block_given?
|
81
|
-
end
|
82
|
-
end
|
90
|
+
def current_namespace
|
91
|
+
@current_namespace ||= []
|
92
|
+
end
|
83
93
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
deep_key = current_namespace.dup << method_name.to_s
|
91
|
-
return ::Chef::CookieCutter::Namespace.deep_fetch!(attributes, deep_key)
|
92
|
-
else
|
93
|
-
vivified[method_name.to_s] = args.size == 1 ? args.first : args
|
94
|
-
return nil
|
94
|
+
def vivified
|
95
|
+
precedence = namespace_options[:precedence]
|
96
|
+
current_namespace.inject(precedence) do |hash, item|
|
97
|
+
hash[item] ||= {}
|
98
|
+
hash[item]
|
99
|
+
end
|
95
100
|
end
|
96
101
|
end
|
97
102
|
end
|
@@ -20,6 +20,12 @@ class Chef
|
|
20
20
|
module RunState
|
21
21
|
module_function
|
22
22
|
|
23
|
+
def register
|
24
|
+
Chef::Recipe.send :include, DSL
|
25
|
+
Chef::Resource.send :include, DSL
|
26
|
+
Chef::Provider.send :include, DSL
|
27
|
+
end
|
28
|
+
|
23
29
|
class RunStateDoesNotExistError < StandardError
|
24
30
|
def initialize(keys, key)
|
25
31
|
hash = keys.map { |k| "['#{k}']" }
|
@@ -43,26 +49,26 @@ EOH
|
|
43
49
|
def fetch_state(node, *keys)
|
44
50
|
keys.map!(&:to_s)
|
45
51
|
keys.inject(node.run_state) do |hash, key|
|
46
|
-
fail
|
52
|
+
fail RunState::RunStateDoesNotExistError.new(keys, key) unless hash.key? key
|
47
53
|
hash[key]
|
48
54
|
end
|
49
55
|
end
|
50
|
-
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
module DSL
|
58
|
+
def store_state(*subkeys, key, value)
|
59
|
+
RunState.store_state(node, *subkeys, key, value)
|
60
|
+
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
def fetch_state(*keys)
|
63
|
+
RunState.fetch_state(node, *keys)
|
64
|
+
end
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
def exist_state?(*keys)
|
67
|
+
RunState.fetch_state(node, *keys)
|
68
|
+
true
|
69
|
+
rescue RunState::RunStateDoesNotExistError
|
70
|
+
false
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
end
|
@@ -20,6 +20,12 @@ class Chef
|
|
20
20
|
module SharedBlocks
|
21
21
|
module_function
|
22
22
|
|
23
|
+
def register
|
24
|
+
Chef::Recipe.send :include, DSL
|
25
|
+
Chef::Resource.send :include, DSL
|
26
|
+
Chef::Provider.send :include, DSL
|
27
|
+
end
|
28
|
+
|
23
29
|
class SharedBlockAlreadyDefined < StandardError
|
24
30
|
def initialize(name)
|
25
31
|
super <<-EOH
|
@@ -36,22 +42,22 @@ The shared block with the name #{name} is not defined.
|
|
36
42
|
EOH
|
37
43
|
end
|
38
44
|
end
|
39
|
-
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
module DSL
|
47
|
+
def shared?(name)
|
48
|
+
exist_state?(:cookie_cutter, :shared_blocks, name)
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def shared(name, &block)
|
52
|
+
fail SharedBlocks::SharedBlockAlreadyDefined, name if shared? name
|
53
|
+
store_state(:cookie_cutter, :shared_blocks, name, block)
|
54
|
+
end
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
def include_shared(name)
|
57
|
+
fail SharedBlocks::SharedBlockNotDefined, name unless shared? name
|
58
|
+
block = fetch_state(:cookie_cutter, :shared_blocks, name)
|
59
|
+
instance_eval(&block)
|
60
|
+
end
|
55
61
|
end
|
56
62
|
end
|
57
63
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2015, Ole Claussen <claussen.ole@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
class Chef
|
19
|
+
module CookieCutter
|
20
|
+
module SpecMatchers
|
21
|
+
module_function
|
22
|
+
|
23
|
+
def register
|
24
|
+
Chef::Resource::LWRPBase.send :prepend, MonkeyPatches::LWRPResource
|
25
|
+
end
|
26
|
+
|
27
|
+
module MonkeyPatches
|
28
|
+
# Monkey Patches for Chef::Resource::LWRPBase
|
29
|
+
# Automatically registers chef spec matchers after building the resource
|
30
|
+
module LWRPResource
|
31
|
+
module ClassMethods
|
32
|
+
def build_from_file(cookbook_name, filename, run_context)
|
33
|
+
resource = super
|
34
|
+
if defined?(ChefSpec) && !resource.is_a?(TrueClass)
|
35
|
+
resource.actions.each do |action|
|
36
|
+
Object.send :define_method, "#{action}_#{resource.resource_name}" do |msg|
|
37
|
+
::ChefSpec::Matchers::ResourceMatcher.new(resource.resource_name, action, msg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
resource
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.prepended(base)
|
46
|
+
class << base
|
47
|
+
prepend ClassMethods
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cookie_cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ole Claussen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,12 +74,14 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- lib/chef/cookie_cutter.rb
|
76
76
|
- lib/chef/cookie_cutter/extended_provides.rb
|
77
|
+
- lib/chef/cookie_cutter/fake_resource.rb
|
77
78
|
- lib/chef/cookie_cutter/fancy_property.rb
|
78
79
|
- lib/chef/cookie_cutter/lwrp_build_params.rb
|
79
80
|
- lib/chef/cookie_cutter/lwrp_include.rb
|
80
81
|
- lib/chef/cookie_cutter/namespace.rb
|
81
82
|
- lib/chef/cookie_cutter/run_state.rb
|
82
83
|
- lib/chef/cookie_cutter/shared_blocks.rb
|
84
|
+
- lib/chef/cookie_cutter/spec_matchers.rb
|
83
85
|
homepage: https://github.com/oclaussen/chef-cookie-cutter
|
84
86
|
licenses:
|
85
87
|
- Apache 2.0
|
@@ -100,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
102
|
version: '0'
|
101
103
|
requirements: []
|
102
104
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.4.5
|
105
|
+
rubygems_version: 2.4.5.1
|
104
106
|
signing_key:
|
105
107
|
specification_version: 4
|
106
108
|
summary: A small collection of Chef hacks and workarounds.
|