poise 2.3.0 → 2.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9346bbce570e141a731a72396f1d1ce0e6da5bae
4
- data.tar.gz: 5a0d996080b83353b59eee2484b657613472d12c
3
+ metadata.gz: 24a33545417d1c2279589178dd1c1d628230c846
4
+ data.tar.gz: f9a198a9b68372bed52ca682a73a7e631d44f895
5
5
  SHA512:
6
- metadata.gz: f53889732b8ffe28dd15938fcb24d87686e4dfc984b3b44807fdbffe3412e0dce62263efa200faf3617f7bfe9beb4b6873a4121d2fbee92adf7477452110e735
7
- data.tar.gz: d06c1b67c3bb6fd46edc21794cd1e28af06d89938e973da7dddeccf1f0eced60ef32295d14b78e6d927e4d8299dbdbdebd49b24c27308097746563b7b880ba32
6
+ metadata.gz: a1a53efeb9ec2e84598b091e95ee2e08ef5060783ed7c5d4c465aa811eefb6353f22553b93f3b34dc82b5752f5ca3258b04141742b50dfa7956c1239059678e7
7
+ data.tar.gz: fbb24556681ffb951dac32d19b879f760cf54bfb7abcda44cf429149d0415343fa780103f4e15e0d26c0352ea37849acf226796cd541d68d827a814ffd4b84c8
@@ -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.class_exec do
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.class_exec { include Chef::DSL::Recipe }
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 !parent && parent_auto
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
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module Poise
19
- VERSION = '2.3.0'
19
+ VERSION = '2.3.1'
20
20
  end
@@ -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.0
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-19 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite