poise 2.3.2 → 2.4.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/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/poise/helpers/inversion.rb +5 -1
- data/lib/poise/helpers/resource_subclass.rb +3 -2
- data/lib/poise/helpers/subresources/child.rb +4 -0
- data/lib/poise/helpers/subresources/container.rb +25 -0
- data/lib/poise/version.rb +1 -1
- data/test/spec/helpers/resource_subclass_spec.rb +19 -2
- data/test/spec/helpers/subresources/container_spec.rb +50 -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: 2670b11e79bcee699172c7eaa7a842df9432324e
|
4
|
+
data.tar.gz: 56e5b571574d41de09f7af34da94034557fa741a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b803a269f764c6a061077d27f608d14e14f572c2e016f3986eeee22adc39bf408683cac41c6714b32bc4ad56dba6d03e87095e1c228d6edebc6d744a685209
|
7
|
+
data.tar.gz: 047b174a37deae87fb3658b6e465be97fe86826028d4575c2f46298d573115eb1c83794289df262b66f6771f9d538ea14f07851aeb139d779cd9f22a38b69874
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v2.4.0
|
4
|
+
|
5
|
+
* Added return value to `Container#register_subresource` to track if the resource
|
6
|
+
was already added.
|
7
|
+
* Improve inspect output for subresources and containers.
|
8
|
+
* Ensure notifications work with subresources.
|
9
|
+
* Inversion providers process name equivalences.
|
10
|
+
|
3
11
|
## v2.3.2
|
4
12
|
|
5
13
|
* Improve handling of deeply nested subresources.
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
## What is Poise?
|
11
11
|
|
12
12
|
The poise cookbook is a set of libraries for writing reusable cookbooks. It
|
13
|
-
|
13
|
+
provides helpers for common patterns and a standard structure to make it easier to create flexible cookbooks.
|
14
14
|
|
15
15
|
## Writing your first resource
|
16
16
|
|
@@ -78,7 +78,11 @@ module Poise
|
|
78
78
|
# end
|
79
79
|
def provider(val=nil)
|
80
80
|
if val && !val.is_a?(Class)
|
81
|
-
|
81
|
+
resource_names = [resource_name]
|
82
|
+
# If subclass_providers! might be in play, check for those names too.
|
83
|
+
resource_names.concat(self.class.subclass_resource_equivalents) if self.class.respond_to?(:subclass_resource_equivalents)
|
84
|
+
# Silly ruby tricks to find the first provider that exists and no more.
|
85
|
+
provider_class = resource_names.lazy.map {|name| Poise::Helpers::Inversion.provider_for(name, node, val) }.select {|x| x }.first
|
82
86
|
Chef::Log.debug("[#{self}] Checking for an inversion provider for #{val}: #{provider_class && provider_class.name}")
|
83
87
|
val = provider_class if provider_class
|
84
88
|
end
|
@@ -27,8 +27,8 @@ module Poise
|
|
27
27
|
include ResourceName
|
28
28
|
|
29
29
|
module ClassMethods
|
30
|
-
def subclass_providers!(superclass_resource_name=nil)
|
31
|
-
resource_name
|
30
|
+
def subclass_providers!(superclass_resource_name=nil, resource_name: nil)
|
31
|
+
resource_name ||= self.resource_name
|
32
32
|
superclass_resource_name ||= if superclass.respond_to?(:resource_name)
|
33
33
|
superclass.resource_name
|
34
34
|
elsif superclass.respond_to?(:dsl_name)
|
@@ -57,6 +57,7 @@ module Poise
|
|
57
57
|
else
|
58
58
|
subclass_resource_equivalents << superclass_resource_name
|
59
59
|
end
|
60
|
+
subclass_resource_equivalents.uniq!
|
60
61
|
end
|
61
62
|
|
62
63
|
# An array of names for the resources this class is equivalent to for
|
@@ -31,6 +31,10 @@ module Poise
|
|
31
31
|
# is used to show the value of @subresources during Chef's error formatting.
|
32
32
|
# @api private
|
33
33
|
class NoPrintingResourceCollection < Chef::ResourceCollection
|
34
|
+
def inspect
|
35
|
+
to_text
|
36
|
+
end
|
37
|
+
|
34
38
|
def to_text
|
35
39
|
"[#{all_resources.map(&:to_s).join(', ')}]"
|
36
40
|
end
|
@@ -80,12 +84,24 @@ module Poise
|
|
80
84
|
end
|
81
85
|
@run_context.resource_collection.insert(order_fixer)
|
82
86
|
@subcontexts.each do |ctx|
|
87
|
+
# Copy all resources to the outer context.
|
83
88
|
ctx.resource_collection.each do |r|
|
84
89
|
Chef::Log.debug(" * #{r}")
|
85
90
|
# Fix the subresource to use the outer run context.
|
86
91
|
r.run_context = @run_context
|
87
92
|
@run_context.resource_collection.insert(r)
|
88
93
|
end
|
94
|
+
# Copy all notifications to the outer context.
|
95
|
+
%w{immediate delayed}.each do |notification_type|
|
96
|
+
ctx.send(:"#{notification_type}_notification_collection").each do |key, notifications|
|
97
|
+
notifications.each do |notification|
|
98
|
+
parent_notifications = @run_context.send(:"#{notification_type}_notification_collection")[key]
|
99
|
+
unless parent_notifications.any? { |existing_notification| existing_notification.duplicates?(notification) }
|
100
|
+
parent_notifications << notification
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
89
105
|
end
|
90
106
|
Chef::Log.debug("Collection: #{@run_context.resource_collection.map(&:to_s).join(', ')}")
|
91
107
|
end
|
@@ -140,11 +156,19 @@ module Poise
|
|
140
156
|
resource.first
|
141
157
|
end
|
142
158
|
|
159
|
+
# Register a resource as part of this container. Returns true if the
|
160
|
+
# resource was added to the collection and false if it was already
|
161
|
+
# known.
|
162
|
+
#
|
163
|
+
# @note Return value added in 2.4.0.
|
164
|
+
# @return [Boolean]
|
143
165
|
def register_subresource(resource)
|
144
166
|
subresources.lookup(resource)
|
167
|
+
false
|
145
168
|
rescue Chef::Exceptions::ResourceNotFound
|
146
169
|
Chef::Log.debug("[#{self}] Adding #{resource} to subresources")
|
147
170
|
subresources.insert(resource)
|
171
|
+
true
|
148
172
|
end
|
149
173
|
|
150
174
|
private
|
@@ -193,6 +217,7 @@ module Poise
|
|
193
217
|
super
|
194
218
|
klass.extend(ClassMethods)
|
195
219
|
klass.const_get(:HIDDEN_IVARS) << :@subcontexts
|
220
|
+
klass.const_get(:FORBIDDEN_IVARS) << :@subcontexts
|
196
221
|
end
|
197
222
|
end
|
198
223
|
|
data/lib/poise/version.rb
CHANGED
@@ -29,7 +29,7 @@ module PoiseTestSubclass
|
|
29
29
|
include Poise
|
30
30
|
provides(:poise_test_subclass)
|
31
31
|
def action_run
|
32
|
-
node.run_state[:really_did_run]
|
32
|
+
(node.run_state[:really_did_run] ||= []) << new_resource.name
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -45,7 +45,24 @@ describe Poise::Helpers::ResourceSubclass do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it { is_expected.to run_poise_sub('test') }
|
48
|
-
it { expect(chef_run.node.run_state[:really_did_run]).to
|
48
|
+
it { expect(chef_run.node.run_state[:really_did_run]).to eq %w{test} }
|
49
|
+
|
50
|
+
context 'with multiple resource names' do
|
51
|
+
before { step_into << :poise_test_subclass_other_name }
|
52
|
+
resource(:poise_sub, parent: PoiseTestSubclass::Resource) do
|
53
|
+
provides(:poise_sub)
|
54
|
+
provides(:poise_test_subclass_other_name)
|
55
|
+
subclass_providers!
|
56
|
+
end
|
57
|
+
recipe do
|
58
|
+
poise_sub 'test'
|
59
|
+
poise_test_subclass_other_name 'test2'
|
60
|
+
end
|
61
|
+
|
62
|
+
it { is_expected.to run_poise_sub('test') }
|
63
|
+
it { is_expected.to ChefSpec::Matchers::ResourceMatcher.new('poise_test_subclass_other_name', 'run', 'test2') }
|
64
|
+
it { expect(chef_run.node.run_state[:really_did_run]).to eq %w{test test2} }
|
65
|
+
end # /context with multiple resource names
|
49
66
|
end # /describe .subclass_providers!
|
50
67
|
|
51
68
|
describe '.subclass_resource_equivalents' do
|
@@ -286,4 +286,54 @@ describe Poise::Helpers::Subresources::Container do
|
|
286
286
|
it { is_expected.to run_poise_child('three').with(parent: chef_run.poise_parent('two'), order: 3) }
|
287
287
|
end # /context un-nested
|
288
288
|
end # /describe triple nesting
|
289
|
+
|
290
|
+
describe 'subresources with notifications' do
|
291
|
+
step_into(:ruby_block)
|
292
|
+
resource(:poise_parent) do
|
293
|
+
include described_class
|
294
|
+
end
|
295
|
+
provider(:poise_parent)
|
296
|
+
resource(:poise_child) do
|
297
|
+
include Poise::Helpers::Subresources::Child
|
298
|
+
parent_type :poise_parent
|
299
|
+
end
|
300
|
+
provider(:poise_child) do
|
301
|
+
def action_run
|
302
|
+
new_resource.updated_by_last_action(true)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
subject { chef_run.node.run_state['poise_notified'] }
|
306
|
+
|
307
|
+
context 'delayed notification' do
|
308
|
+
recipe(subject: false) do
|
309
|
+
ruby_block 'one' do
|
310
|
+
action :nothing
|
311
|
+
block { node.run_state['poise_notified'] = true }
|
312
|
+
end
|
313
|
+
poise_parent 'two' do
|
314
|
+
poise_child 'three' do
|
315
|
+
notifies :run, 'ruby_block[one]', :delayed
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
it { is_expected.to be true }
|
321
|
+
end # /context delayed notification
|
322
|
+
|
323
|
+
context 'immediate notification' do
|
324
|
+
recipe(subject: false) do
|
325
|
+
ruby_block 'one' do
|
326
|
+
action :nothing
|
327
|
+
block { node.run_state['poise_notified'] = true }
|
328
|
+
end
|
329
|
+
poise_parent 'two' do
|
330
|
+
poise_child 'three' do
|
331
|
+
notifies :run, 'ruby_block[one]', :immediately
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it { is_expected.to be true }
|
337
|
+
end # /context immediate notification
|
338
|
+
end # /describe subresources with notifications
|
289
339
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Kantrowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: halite
|