chef-cookie_cutter 0.2.0 → 1.0.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/extended_provides/monkey_patches.rb +39 -0
- data/lib/chef/cookie_cutter/extended_provides.rb +5 -22
- data/lib/chef/cookie_cutter/fancy_property/cookbook_doc.rb +48 -0
- data/lib/chef/cookie_cutter/fancy_property/property.rb +150 -0
- data/lib/chef/cookie_cutter/fancy_property.rb +4 -162
- data/lib/chef/cookie_cutter/include_properties/dsl.rb +40 -0
- data/lib/chef/cookie_cutter/include_properties/errors.rb +41 -0
- data/lib/chef/cookie_cutter/include_properties.rb +33 -0
- data/lib/chef/cookie_cutter/{lwrp_include.rb → include_resource/cookbook_doc.rb} +5 -62
- data/lib/chef/cookie_cutter/include_resource/dsl.rb +56 -0
- data/lib/chef/cookie_cutter/include_resource/fake_resource.rb +40 -0
- data/lib/chef/cookie_cutter/include_resource/monkey_patches.rb +42 -0
- data/lib/chef/cookie_cutter/include_resource.rb +39 -0
- data/lib/chef/cookie_cutter/{fake_resource.rb → namespace/dsl.rb} +8 -15
- data/lib/chef/cookie_cutter/namespace/monkey_patches.rb +67 -0
- data/lib/chef/cookie_cutter/namespace/namespace.rb +46 -0
- data/lib/chef/cookie_cutter/namespace.rb +12 -82
- data/lib/chef/cookie_cutter/run_state/dsl.rb +50 -0
- data/lib/chef/cookie_cutter/run_state/errors.rb +34 -0
- data/lib/chef/cookie_cutter/run_state.rb +8 -51
- data/lib/chef/cookie_cutter/spec_matchers/monkey_patches.rb +48 -0
- data/lib/chef/cookie_cutter/spec_matchers.rb +3 -30
- data/lib/chef/cookie_cutter/version.rb +22 -0
- data/lib/chef/cookie_cutter.rb +3 -18
- metadata +20 -6
- data/lib/chef/cookie_cutter/lwrp_build_params.rb +0 -71
- data/lib/chef/cookie_cutter/shared_blocks.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f8d1f2d2e240ce7fc042f2eb7cd00faf800848
|
4
|
+
data.tar.gz: 28fafa9dd01fc4f4803b6d187f6dbfb40cb75ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c203b0f3b695aab6074c8719edc2c1e2e12d58b5d0d6cc494560fdd8019e1b13f0ea2791141fd21f1a6660703b0d4202f18ea05015d67389c886e2af91452a4
|
7
|
+
data.tar.gz: 76f64c329450c0b2ce2c28b39da21557d80f03335ec20e154fa07c5dfbe8ea9190a7b6a350452690930e6679f826980b6dfeeaad06460e65d28c4192ca789b47
|
@@ -0,0 +1,39 @@
|
|
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 ExtendedProvides
|
21
|
+
module MonkeyPatches
|
22
|
+
module RunContext
|
23
|
+
attr_reader :resource_builder
|
24
|
+
|
25
|
+
def build_resource(builder)
|
26
|
+
@resource_builder = builder
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ResourceBuilder
|
31
|
+
def build(&block)
|
32
|
+
run_context.build_resource(self)
|
33
|
+
super(&block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -14,33 +14,16 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
|
+
require 'chef/run_context'
|
18
|
+
require 'chef/resource_builder'
|
17
19
|
|
18
20
|
class Chef
|
19
21
|
module CookieCutter
|
20
22
|
module ExtendedProvides
|
21
|
-
|
23
|
+
require_relative 'extended_provides/monkey_patches'
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
Chef::ResourceBuilder.send :prepend, MonkeyPatches::ResourceBuilder
|
26
|
-
end
|
27
|
-
|
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
|
42
|
-
end
|
43
|
-
end
|
25
|
+
::Chef::RunContext.send :prepend, MonkeyPatches::RunContext
|
26
|
+
::Chef::ResourceBuilder.send :prepend, MonkeyPatches::ResourceBuilder
|
44
27
|
end
|
45
28
|
end
|
46
29
|
end
|
@@ -0,0 +1,48 @@
|
|
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 FancyPropertyModule
|
21
|
+
module MonkeyPatches
|
22
|
+
# Monkey Patches for KnifeCookbookDoc::ResourceModel
|
23
|
+
# Enriches attribute/property description with additional info
|
24
|
+
# if certain options are passed to FancyProperty
|
25
|
+
# Removes argument declaration from description if present, and makes
|
26
|
+
# it available accessor
|
27
|
+
module DocumentResourceModel
|
28
|
+
ARGS_REGEX = /@args\s*\(([^\(\)]+)\)\s*(.*)/
|
29
|
+
|
30
|
+
def attribute_description(attribute)
|
31
|
+
description = attribute_descriptions[attribute.to_s] || ''
|
32
|
+
description = ARGS_REGEX.match(description)[2] if description =~ ARGS_REGEX
|
33
|
+
opts = @native_resource.attribute_specifications[attribute]
|
34
|
+
description += " Must be a `#{opts[:coerce_resource]}` resource or a block." if opts.key?(:coerce_resource)
|
35
|
+
description += ' This attribute can be specified multiple times.' if opts.key?(:collect)
|
36
|
+
description
|
37
|
+
end
|
38
|
+
|
39
|
+
def attribute_arguments(attribute)
|
40
|
+
description = attribute_descriptions[attribute.to_s]
|
41
|
+
return [] unless description =~ ARGS_REGEX
|
42
|
+
ARGS_REGEX.match(description)[1].split(',').map(&:strip)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,150 @@
|
|
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
|
+
class FancyProperty < ::Chef::Property
|
21
|
+
def call(resource, *args, **kwargs, &blk)
|
22
|
+
return get(resource) if args.empty? && kwargs.empty? && !block_given?
|
23
|
+
return get(resource) if args[0] == NOT_PASSED
|
24
|
+
set(resource, *args, **kwargs, &blk)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(resource)
|
28
|
+
if instance_variable_name && collect? && !is_set?(resource)
|
29
|
+
[]
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def set(resource, *args, **kwargs, &blk)
|
36
|
+
if args[0].is_a?(DelayedEvaluator)
|
37
|
+
set_value(resource, args[0])
|
38
|
+
else
|
39
|
+
value = coerce(resource, *args, **kwargs, &blk)
|
40
|
+
validate(resource, value)
|
41
|
+
set_value(resource, value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def coerce(resource, *args, **kwargs, &blk)
|
46
|
+
if options.key?(:coerce_class)
|
47
|
+
value = coerce_class(options[:coerce_class], *args, **kwargs, &blk)
|
48
|
+
value = coerce_proc(resource, options[:coerce], value) if options.key?(:coerce)
|
49
|
+
value
|
50
|
+
elsif options.key?(:coerce_resource)
|
51
|
+
value = coerce_resource(resource, options[:coerce_resource], args[0], &blk)
|
52
|
+
value = coerce_proc(resource, options[:coerce], value) if options.key?(:coerce)
|
53
|
+
value
|
54
|
+
elsif options.key?(:coerce)
|
55
|
+
coerce_proc(resource, options[:coerce], *args, **kwargs, &blk)
|
56
|
+
elsif args.length == 1 && kwargs.empty?
|
57
|
+
args[0]
|
58
|
+
else
|
59
|
+
fail Chef::Exceptions::ValidationFailed, "No coercion given for arguments #{args}, #{kwargs}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def coerce_class(clazz, *args, **kwargs, &blk)
|
64
|
+
args << kwargs unless kwargs.empty?
|
65
|
+
value = clazz.new(*args)
|
66
|
+
value.instance_eval(&blk) if block_given?
|
67
|
+
value
|
68
|
+
end
|
69
|
+
|
70
|
+
def coerce_resource(resource, resource_type, value, &blk)
|
71
|
+
return value if value.is_a?(::Chef::Resource) && value.declared_type == resource_type
|
72
|
+
new_resource = ::Chef::ResourceBuilder.new(
|
73
|
+
type: resource_type,
|
74
|
+
name: value,
|
75
|
+
created_at: caller[0],
|
76
|
+
params: nil,
|
77
|
+
run_context: resource.run_context,
|
78
|
+
cookbook_name: resource.cookbook_name,
|
79
|
+
recipe_name: resource.recipe_name,
|
80
|
+
enclosing_provider: nil
|
81
|
+
).build(&blk)
|
82
|
+
resource.run_context.resource_collection.insert(
|
83
|
+
new_resource,
|
84
|
+
resource_type: resource_type,
|
85
|
+
instance_name: value
|
86
|
+
)
|
87
|
+
new_resource
|
88
|
+
end
|
89
|
+
|
90
|
+
def coerce_proc(resource, coerce, *args, **kwargs, &blk)
|
91
|
+
args << kwargs unless kwargs.empty?
|
92
|
+
value = resource.instance_exec(*args, &coerce) unless resource.nil?
|
93
|
+
value.instance_eval(&blk) if block_given?
|
94
|
+
value = coerce(resource, value) if value.is_a?(DelayedEvaluator)
|
95
|
+
value
|
96
|
+
end
|
97
|
+
|
98
|
+
def emit_dsl
|
99
|
+
return unless instance_variable_name
|
100
|
+
|
101
|
+
if allow_kwargs?
|
102
|
+
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
103
|
+
def #{name}(*args, **kwargs, &blk)
|
104
|
+
self.class.properties[#{name.inspect}].call(self, *args, **kwargs, &blk)
|
105
|
+
end
|
106
|
+
EOM
|
107
|
+
else
|
108
|
+
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
109
|
+
def #{name}(value=NOT_PASSED, &blk)
|
110
|
+
self.class.properties[#{name.inspect}].call(self, value, {}, &blk)
|
111
|
+
end
|
112
|
+
def #{name}=(value)
|
113
|
+
self.class.properties[#{name.inspect}].set(self, value, {})
|
114
|
+
end
|
115
|
+
EOM
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def collect?
|
120
|
+
options[:collect]
|
121
|
+
end
|
122
|
+
|
123
|
+
def allow_kwargs?
|
124
|
+
return true if options[:allow_kwargs]
|
125
|
+
return true if options.key?(:coerce) && options[:coerce].arity != 1
|
126
|
+
return true if options.key?(:coerce_class) && options[:coerce_class].instance_method(:initialize).arity != 1
|
127
|
+
false
|
128
|
+
end
|
129
|
+
|
130
|
+
def validation_options
|
131
|
+
@validation_options ||= options.reject do |k, _|
|
132
|
+
[
|
133
|
+
:declared_in, :name, :instance_variable_name, :desired_state,
|
134
|
+
:identity, :default, :name_property, :coerce, :required, :collect,
|
135
|
+
:allow_kwargs, :coerce_class, :coerce_resource
|
136
|
+
].include?(k)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def set_value(resource, value)
|
141
|
+
if instance_variable_name && collect?
|
142
|
+
resource.instance_variable_set(instance_variable_name, []) unless is_set?(resource)
|
143
|
+
get_value(resource) << value
|
144
|
+
else
|
145
|
+
super
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -23,169 +23,11 @@ class Chef
|
|
23
23
|
|
24
24
|
module CookieCutter
|
25
25
|
module FancyPropertyModule
|
26
|
-
|
26
|
+
require_relative 'fancy_property/property'
|
27
|
+
require_relative 'fancy_property/cookbook_doc'
|
27
28
|
|
28
|
-
|
29
|
-
|
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
|
-
|
62
|
-
class FancyProperty < ::Chef::Property
|
63
|
-
def call(resource, *args, **kwargs, &blk)
|
64
|
-
return get(resource) if args.empty? && kwargs.empty? && !block_given?
|
65
|
-
return get(resource) if args[0] == NOT_PASSED
|
66
|
-
set(resource, *args, **kwargs, &blk)
|
67
|
-
end
|
68
|
-
|
69
|
-
def get(resource)
|
70
|
-
if instance_variable_name && collect? && !is_set?(resource)
|
71
|
-
[]
|
72
|
-
else
|
73
|
-
super
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def set(resource, *args, **kwargs, &blk)
|
78
|
-
if args[0].is_a?(DelayedEvaluator)
|
79
|
-
set_value(resource, args[0])
|
80
|
-
else
|
81
|
-
value = coerce(resource, *args, **kwargs, &blk)
|
82
|
-
validate(resource, value)
|
83
|
-
set_value(resource, value)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def coerce(resource, *args, **kwargs, &blk)
|
88
|
-
if options.key?(:coerce_class)
|
89
|
-
value = coerce_class(options[:coerce_class], *args, **kwargs, &blk)
|
90
|
-
value = coerce_proc(resource, options[:coerce], value) if options.key?(:coerce)
|
91
|
-
value
|
92
|
-
elsif options.key?(:coerce_resource)
|
93
|
-
value = coerce_resource(resource, options[:coerce_resource], args[0], &blk)
|
94
|
-
value = coerce_proc(resource, options[:coerce], value) if options.key?(:coerce)
|
95
|
-
value
|
96
|
-
elsif options.key?(:coerce)
|
97
|
-
coerce_proc(resource, options[:coerce], *args, **kwargs, &blk)
|
98
|
-
elsif args.length == 1 && kwargs.empty?
|
99
|
-
args[0]
|
100
|
-
else
|
101
|
-
fail Chef::Exceptions::ValidationFailed, "No coercion given for arguments #{args}, #{kwargs}"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def coerce_class(clazz, *args, **kwargs, &blk)
|
106
|
-
args << kwargs unless kwargs.empty?
|
107
|
-
value = clazz.new(*args)
|
108
|
-
value.instance_eval(&blk) if block_given?
|
109
|
-
value
|
110
|
-
end
|
111
|
-
|
112
|
-
def coerce_resource(resource, resource_type, value, &blk)
|
113
|
-
return value if value.is_a?(::Chef::Resource) && value.declared_type == resource_type
|
114
|
-
new_resource = ::Chef::ResourceBuilder.new(
|
115
|
-
type: resource_type,
|
116
|
-
name: value,
|
117
|
-
created_at: caller[0],
|
118
|
-
params: nil,
|
119
|
-
run_context: resource.run_context,
|
120
|
-
cookbook_name: resource.cookbook_name,
|
121
|
-
recipe_name: resource.recipe_name,
|
122
|
-
enclosing_provider: nil
|
123
|
-
).build(&blk)
|
124
|
-
resource.run_context.resource_collection.insert(
|
125
|
-
new_resource,
|
126
|
-
resource_type: resource_type,
|
127
|
-
instance_name: value
|
128
|
-
)
|
129
|
-
new_resource
|
130
|
-
end
|
131
|
-
|
132
|
-
def coerce_proc(resource, coerce, *args, **kwargs, &blk)
|
133
|
-
args << kwargs unless kwargs.empty?
|
134
|
-
value = resource.instance_exec(*args, &coerce) unless resource.nil?
|
135
|
-
value.instance_eval(&blk) if block_given?
|
136
|
-
value = coerce(resource, value) if value.is_a?(DelayedEvaluator)
|
137
|
-
value
|
138
|
-
end
|
139
|
-
|
140
|
-
def emit_dsl
|
141
|
-
return unless instance_variable_name
|
142
|
-
|
143
|
-
if allow_kwargs?
|
144
|
-
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
145
|
-
def #{name}(*args, **kwargs, &blk)
|
146
|
-
self.class.properties[#{name.inspect}].call(self, *args, **kwargs, &blk)
|
147
|
-
end
|
148
|
-
EOM
|
149
|
-
else
|
150
|
-
declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
151
|
-
def #{name}(value=NOT_PASSED, &blk)
|
152
|
-
self.class.properties[#{name.inspect}].call(self, value, {}, &blk)
|
153
|
-
end
|
154
|
-
def #{name}=(value)
|
155
|
-
self.class.properties[#{name.inspect}].set(self, value, {})
|
156
|
-
end
|
157
|
-
EOM
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def collect?
|
162
|
-
options[:collect]
|
163
|
-
end
|
164
|
-
|
165
|
-
def allow_kwargs?
|
166
|
-
return true if options[:allow_kwargs]
|
167
|
-
return true if options.key?(:coerce) && options[:coerce].arity != 1
|
168
|
-
return true if options.key?(:coerce_class) && options[:coerce_class].instance_method(:initialize).arity != 1
|
169
|
-
false
|
170
|
-
end
|
171
|
-
|
172
|
-
def validation_options
|
173
|
-
@validation_options ||= options.reject do |k, _|
|
174
|
-
[
|
175
|
-
:declared_in, :name, :instance_variable_name, :desired_state,
|
176
|
-
:identity, :default, :name_property, :coerce, :required, :collect,
|
177
|
-
:allow_kwargs, :coerce_class, :coerce_resource
|
178
|
-
].include?(k)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def set_value(resource, value)
|
183
|
-
if instance_variable_name && collect?
|
184
|
-
resource.instance_variable_set(instance_variable_name, []) unless is_set?(resource)
|
185
|
-
get_value(resource) << value
|
186
|
-
else
|
187
|
-
super
|
188
|
-
end
|
29
|
+
if defined?(KnifeCookbookDoc)
|
30
|
+
KnifeCookbookDoc::ResourceModel.send :prepend, MonkeyPatches::DocumentResourceModel
|
189
31
|
end
|
190
32
|
end
|
191
33
|
end
|
@@ -0,0 +1,40 @@
|
|
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
|
+
require_relative 'errors'
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
module CookieCutter
|
21
|
+
module IncludeProperties
|
22
|
+
module DSL
|
23
|
+
def properties_shared?(name)
|
24
|
+
exist_state?(:cookie_cutter, :shared_properties, name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def share_properties(name, &block)
|
28
|
+
fail Errors::SharedPropertiesAlreadyDefined, name if properties_shared? name
|
29
|
+
store_state(:cookie_cutter, :shared_properties, name, block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def include_properties(name)
|
33
|
+
fail Errors::SharedPropertiesNotDefined, name unless properties_shared? name
|
34
|
+
block = fetch_state(:cookie_cutter, :shared_properties, name)
|
35
|
+
instance_eval(&block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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 IncludeProperties
|
21
|
+
module Errors
|
22
|
+
class SharedPropertiesAlreadyDefined < StandardError
|
23
|
+
def initialize(name)
|
24
|
+
super <<-EOH
|
25
|
+
A shared property set with the name #{name} already exists. Please make sure that
|
26
|
+
every shared property set you define has a unique name.
|
27
|
+
EOH
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class SharedPropertiesNotDefined < StandardError
|
32
|
+
def initialize(name)
|
33
|
+
super <<-EOH
|
34
|
+
A property set with the name #{name} has not been shared.
|
35
|
+
EOH
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
require 'chef/recipe'
|
18
|
+
require 'chef/resource'
|
19
|
+
require 'chef/provider'
|
20
|
+
require_relative 'run_state'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
module CookieCutter
|
24
|
+
module IncludeProperties
|
25
|
+
require_relative 'include_properties/dsl'
|
26
|
+
require_relative 'include_properties/errors'
|
27
|
+
|
28
|
+
::Chef::Recipe.send :include, DSL
|
29
|
+
::Chef::Resource.send :include, DSL
|
30
|
+
::Chef::Provider.send :include, DSL
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -17,70 +17,13 @@
|
|
17
17
|
|
18
18
|
class Chef
|
19
19
|
module CookieCutter
|
20
|
-
module
|
21
|
-
|
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
|
-
|
37
|
-
def try_file(filename)
|
38
|
-
return if File.exist?(filename) && File.readable?(filename)
|
39
|
-
fail IOError, "Cannot open or read #{filename}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def filename_for_record(run_context, cookbook_name, segment, name)
|
43
|
-
name += '.rb' unless name.end_with?('.rb')
|
44
|
-
cookbook_version = run_context.cookbook_collection[cookbook_name]
|
45
|
-
file_vendor = ::Chef::Cookbook::FileVendor.create_from_manifest(cookbook_version.manifest)
|
46
|
-
manifest_record = cookbook_version.preferred_manifest_record(run_context.node, segment.to_s, name)
|
47
|
-
file_vendor.get_filename(manifest_record[:path])
|
48
|
-
end
|
49
|
-
|
50
|
-
def build_resource_module_from_file(filename)
|
51
|
-
try_file(filename)
|
52
|
-
resource_module = Module.new
|
53
|
-
resource_module.instance_variable_set('@filename', filename)
|
54
|
-
def resource_module.included(cls)
|
55
|
-
cls.class_eval(IO.read(@filename), @filename, 1)
|
56
|
-
end
|
57
|
-
resource_module
|
58
|
-
end
|
59
|
-
|
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
|
76
|
-
end
|
77
|
-
|
78
|
-
module DocumentingResourceDSL
|
20
|
+
module IncludeResource
|
21
|
+
module CookbookDocDSL
|
79
22
|
def mixins
|
80
23
|
@mixins ||= []
|
81
24
|
end
|
82
25
|
|
83
|
-
def
|
26
|
+
def include_resource(name, cookbook: nil)
|
84
27
|
mixins << { name: name, cookbook: cookbook }
|
85
28
|
end
|
86
29
|
end
|
@@ -107,7 +50,7 @@ class Chef
|
|
107
50
|
end
|
108
51
|
|
109
52
|
# Monkey Patches for KnifeCookbookDoc::ResourceModel
|
110
|
-
# Overwrites load_descriptions to additionally check if a
|
53
|
+
# Overwrites load_descriptions to additionally check if a resource is a mixin.
|
111
54
|
# Saves cookbook and file name in instance variables
|
112
55
|
module DocumentResourceModel
|
113
56
|
def initialize(cookbook_name, file)
|
@@ -138,7 +81,7 @@ class Chef
|
|
138
81
|
@native_resource.description.each_line do |line|
|
139
82
|
if /^ *\@action *([^ ]*) (.*)$/ =~ line
|
140
83
|
action_descriptions[$1] = $2.strip
|
141
|
-
elsif /^
|
84
|
+
elsif /^ *(?:\@attribute|\@property) *([^ ]*) (.*)$/ =~ line
|
142
85
|
attribute_descriptions[$1] = $2.strip
|
143
86
|
elsif /^ *\@section (.*)$/ =~ line
|
144
87
|
current_section = $1.strip
|