poise 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/poise/helpers/lwrp_polyfill.rb +13 -11
- data/lib/poise/helpers/subresources/child.rb +7 -4
- data/lib/poise/helpers/subresources/default_containers.rb +2 -2
- data/lib/poise/version.rb +1 -1
- data/test/spec/helpers/lwrp_polyfill_spec.rb +12 -0
- data/test/spec/helpers/subresources/child_spec.rb +17 -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: 24a33545417d1c2279589178dd1c1d628230c846
|
4
|
+
data.tar.gz: f9a198a9b68372bed52ca682a73a7e631d44f895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1a53efeb9ec2e84598b091e95ee2e08ef5060783ed7c5d4c465aa811eefb6353f22553b93f3b34dc82b5752f5ca3258b04141742b50dfa7956c1239059678e7
|
7
|
+
data.tar.gz: fbb24556681ffb951dac32d19b879f760cf54bfb7abcda44cf429149d0415343fa780103f4e15e0d26c0352ea37849acf226796cd541d68d827a814ffd4b84c8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v2.3.1
|
4
|
+
|
5
|
+
* Ensure a container with a parent link to its own type doesn't use self as the
|
6
|
+
default parent.
|
7
|
+
* Improve handling of `load_current_resource` in providers that call it via
|
8
|
+
`super`.
|
9
|
+
|
3
10
|
## v2.3.0
|
4
11
|
|
5
12
|
* New helper: `ResourceSubclass`, a helper for subclassing a resource while
|
@@ -129,6 +129,17 @@ module Poise
|
|
129
129
|
|
130
130
|
# Helper to handle load_current_resource for direct subclasses of Provider
|
131
131
|
module Provider
|
132
|
+
module LoadCurrentResource
|
133
|
+
def load_current_resource
|
134
|
+
@current_resource = if new_resource
|
135
|
+
new_resource.class.new(new_resource.name, run_context)
|
136
|
+
else
|
137
|
+
# Better than nothing, subclass can overwrite anyway.
|
138
|
+
Chef::Resource.new(nil, run_context)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
132
143
|
# @!classmethods
|
133
144
|
module ClassMethods
|
134
145
|
def included(klass)
|
@@ -137,20 +148,11 @@ module Poise
|
|
137
148
|
|
138
149
|
# Mask Chef::Provider#load_current_resource because it throws NotImplementedError.
|
139
150
|
if klass.is_a?(Class) && klass.superclass == Chef::Provider
|
140
|
-
klass.
|
141
|
-
def load_current_resource
|
142
|
-
@current_resource = if new_resource
|
143
|
-
new_resource.class.new(new_resource.name, run_context)
|
144
|
-
else
|
145
|
-
# Better than nothing, subclass can overwrite anyway.
|
146
|
-
Chef::Resource.new(nil, run_context)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
151
|
+
klass.send(:include, LoadCurrentResource)
|
150
152
|
end
|
151
153
|
|
152
154
|
# Reinstate the Chef DSL, removed in Chef 12.
|
153
|
-
klass.
|
155
|
+
klass.send(:include, Chef::DSL::Recipe)
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
@@ -92,7 +92,7 @@ module Poise
|
|
92
92
|
val = args.first
|
93
93
|
if val.nil?
|
94
94
|
# Unsetting the parent.
|
95
|
-
parent = nil
|
95
|
+
parent = parent_ref = nil
|
96
96
|
else
|
97
97
|
if val.is_a?(String) && !val.include?('[')
|
98
98
|
raise Poise::Error.new("Cannot use a string #{name} without defining a parent type") if parent_type == Chef::Resource
|
@@ -117,8 +117,8 @@ module Poise
|
|
117
117
|
if !parent.is_a?(parent_type)
|
118
118
|
raise Poise::Error.new("Parent resource is not an instance of #{parent_type.name}: #{val.inspect}")
|
119
119
|
end
|
120
|
+
parent_ref = ParentRef.new(parent)
|
120
121
|
end
|
121
|
-
parent_ref = ParentRef.new(parent)
|
122
122
|
elsif !parent_ref || !parent_ref.resource
|
123
123
|
if parent_default
|
124
124
|
parent = if parent_default.is_a?(Chef::DelayedEvaluator)
|
@@ -127,11 +127,14 @@ module Poise
|
|
127
127
|
parent_default
|
128
128
|
end
|
129
129
|
end
|
130
|
-
if
|
130
|
+
# The @parent_ref means we won't run this if we previously set
|
131
|
+
# ParentRef.new(nil). This means auto-lookup only happens during
|
132
|
+
# after_created.
|
133
|
+
if !parent && !parent_ref && parent_auto
|
131
134
|
# Automatic sibling lookup for sequential composition.
|
132
135
|
# Find the last instance of the parent class as the default parent.
|
133
136
|
# This is super flaky and should only be a last resort.
|
134
|
-
parent = Poise::Helpers::Subresources::DefaultContainers.find(parent_type, run_context)
|
137
|
+
parent = Poise::Helpers::Subresources::DefaultContainers.find(parent_type, run_context, self_resource: self)
|
135
138
|
end
|
136
139
|
# Can't find a valid parent, if it wasn't optional raise an error.
|
137
140
|
raise Poise::Error.new("No #{name} found for #{self}") unless parent || parent_optional
|
@@ -47,10 +47,10 @@ module Poise
|
|
47
47
|
# @param klass [Class] Resource class to search for.
|
48
48
|
# @param run_context [Chef::RunContext] Context of the current run.
|
49
49
|
# @return [Chef::Resource]
|
50
|
-
def self.find(klass, run_context)
|
50
|
+
def self.find(klass, run_context, self_resource: nil)
|
51
51
|
CONTAINER_MUTEX.synchronize do
|
52
52
|
containers(run_context).reverse_each do |resource|
|
53
|
-
return resource if resource.is_a?(klass)
|
53
|
+
return resource if resource.is_a?(klass) && (!self_resource || self_resource != resource)
|
54
54
|
end
|
55
55
|
# Nothing found.
|
56
56
|
nil
|
data/lib/poise/version.rb
CHANGED
@@ -149,6 +149,18 @@ describe Poise::Helpers::LWRPPolyfill do
|
|
149
149
|
it { is_expected.to be_a Chef::Resource }
|
150
150
|
it { is_expected.to_not be_a resource(:poise_test) }
|
151
151
|
end # context with no new_resource
|
152
|
+
|
153
|
+
context 'calling super' do
|
154
|
+
provider(:poise_test, auto: false) do
|
155
|
+
include described_class
|
156
|
+
def load_current_resource
|
157
|
+
super.tap do |current_resource|
|
158
|
+
current_resource.name('other')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
its(:name) { is_expected.to eq 'other' }
|
163
|
+
end # /context calling super
|
152
164
|
end # /describe load_current_resource override
|
153
165
|
|
154
166
|
describe 'Chef::DSL::Recipe include' do
|
@@ -333,6 +333,23 @@ describe Poise::Helpers::Subresources::Child do
|
|
333
333
|
|
334
334
|
it { expect { subject }.to raise_error Poise::Error }
|
335
335
|
end # /context setting the parent to itself
|
336
|
+
|
337
|
+
context 'when possibly setting to self via default' do
|
338
|
+
resource(:poise_test) do
|
339
|
+
include described_class
|
340
|
+
include Poise::Helpers::ResourceName
|
341
|
+
include Poise::Helpers::Subresources::Container
|
342
|
+
parent_type :poise_test
|
343
|
+
parent_optional true
|
344
|
+
end
|
345
|
+
recipe do
|
346
|
+
poise_test 'one'
|
347
|
+
poise_test 'two'
|
348
|
+
end
|
349
|
+
|
350
|
+
it { is_expected.to run_poise_test('one').with(parent: nil) }
|
351
|
+
it { is_expected.to run_poise_test('two').with(parent: chef_run.poise_test('one')) }
|
352
|
+
end # /context when possibly setting to self via default
|
336
353
|
end # /describe #parent
|
337
354
|
|
338
355
|
describe '.parent_type' do
|
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.3.
|
4
|
+
version: 2.3.1
|
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-08-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: halite
|