poise 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a33545417d1c2279589178dd1c1d628230c846
4
- data.tar.gz: f9a198a9b68372bed52ca682a73a7e631d44f895
3
+ metadata.gz: 4fb584605a370cd20300d0456630ffe8a0d5351a
4
+ data.tar.gz: 7df0b817befc116a8cb5e8729ee604707771ae1b
5
5
  SHA512:
6
- metadata.gz: a1a53efeb9ec2e84598b091e95ee2e08ef5060783ed7c5d4c465aa811eefb6353f22553b93f3b34dc82b5752f5ca3258b04141742b50dfa7956c1239059678e7
7
- data.tar.gz: fbb24556681ffb951dac32d19b879f760cf54bfb7abcda44cf429149d0415343fa780103f4e15e0d26c0352ea37849acf226796cd541d68d827a814ffd4b84c8
6
+ metadata.gz: fc97265d1907474050c72893815a35c1b20a31dbd1740bdb8d05ab70a60fb9e28dc0850a1afc52ad4202a49834c99580c2f139e8133cbcc5401af01c7c47aff9
7
+ data.tar.gz: d4c49153950ba2736fba3d4f24054543edd4cf2c464205a40a73dca08257288ce8de497db11b8025da080cb76c76cedafb56dd320d6e367eab1e508b065aadd8
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.3.2
4
+
5
+ * Improve handling of deeply nested subresources.
6
+
3
7
  ## v2.3.1
4
8
 
5
9
  * Ensure a container with a parent link to its own type doesn't use self as the
@@ -40,10 +40,12 @@ module Poise
40
40
  include Chef::DSL::Recipe
41
41
 
42
42
  attr_reader :subresources
43
+ attr_reader :subcontexts
43
44
 
44
45
  def initialize(*args)
45
46
  super
46
47
  @subresources = NoPrintingResourceCollection.new
48
+ @subcontexts = []
47
49
  end
48
50
 
49
51
  def after_created
@@ -74,12 +76,18 @@ module Poise
74
76
  # Step back so we re-run the "current" resource, which is now the
75
77
  # container.
76
78
  collection.iterator.skip_back
79
+ Chef::Log.debug("Collection: #{@run_context.resource_collection.map(&:to_s).join(', ')}")
77
80
  end
78
81
  @run_context.resource_collection.insert(order_fixer)
79
- @subresources.each do |r|
80
- Chef::Log.debug(" * #{r}")
81
- @run_context.resource_collection.insert(r)
82
+ @subcontexts.each do |ctx|
83
+ ctx.resource_collection.each do |r|
84
+ Chef::Log.debug(" * #{r}")
85
+ # Fix the subresource to use the outer run context.
86
+ r.run_context = @run_context
87
+ @run_context.resource_collection.insert(r)
88
+ end
82
89
  end
90
+ Chef::Log.debug("Collection: #{@run_context.resource_collection.map(&:to_s).join(', ')}")
83
91
  end
84
92
  end
85
93
 
@@ -93,7 +101,7 @@ module Poise
93
101
  created_at ||= caller[0]
94
102
  # Run this inside a subcontext to avoid adding to the current resource collection.
95
103
  # It will end up added later, indirected via @subresources to ensure ordering.
96
- subcontext_block do
104
+ @subcontexts << subcontext_block do
97
105
  namespace = if self.class.container_namespace == true
98
106
  # If the value is true, use the name of the container resource.
99
107
  self.name
@@ -184,6 +192,7 @@ module Poise
184
192
  def included(klass)
185
193
  super
186
194
  klass.extend(ClassMethods)
195
+ klass.const_get(:HIDDEN_IVARS) << :@subcontexts
187
196
  end
188
197
  end
189
198
 
@@ -161,6 +161,11 @@ module Poise
161
161
  # @param args [Array<Object>] Arguments to check.
162
162
  # @return [void]
163
163
  def check_block_arity!(block, args)
164
+ # Convert the block to a lambda-style proc. You can't make this shit up.
165
+ obj = Object.new
166
+ obj.define_singleton_method(:block, &block)
167
+ block = obj.method(:block).to_proc
168
+ # Check
164
169
  required_args = block.arity < 0 ? ~block.arity : block.arity
165
170
  if args.length < required_args || (block.arity >= 0 && args.length > block.arity)
166
171
  raise ArgumentError.new("wrong number of arguments (#{args.length} for #{required_args}#{block.arity < 0 ? '+' : ''})")
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module Poise
19
- VERSION = '2.3.1'
19
+ VERSION = '2.3.2'
20
20
  end
@@ -15,6 +15,7 @@
15
15
  #
16
16
 
17
17
  require 'spec_helper'
18
+ require 'chef/provider_resolver'
18
19
 
19
20
  describe Poise::Helpers::Inversion do
20
21
  describe Poise::Helpers::Inversion::Resource do
@@ -224,4 +224,66 @@ describe Poise::Helpers::Subresources::Container do
224
224
  it { is_expected.to run_poise_sub('test') }
225
225
  it { is_expected.to run_inner('test::one') }
226
226
  end # /describe subclassing a container
227
+
228
+ describe 'triple nesting' do
229
+ resource(:poise_grandparent) do
230
+ include described_class
231
+ attr_accessor :order
232
+ end
233
+ provider(:poise_grandparent) do
234
+ def action_run
235
+ new_resource.order = (node.run_state[:order] += 1)
236
+ end
237
+ end
238
+ resource(:poise_parent) do
239
+ include described_class
240
+ include Poise::Helpers::Subresources::Child
241
+ parent_type :poise_grandparent
242
+ attr_accessor :order
243
+ end
244
+ provider(:poise_parent) do
245
+ def action_run
246
+ new_resource.order = (node.run_state[:order] += 1)
247
+ end
248
+ end
249
+ resource(:poise_child) do
250
+ include described_class
251
+ include Poise::Helpers::Subresources::Child
252
+ parent_type :poise_parent
253
+ attr_accessor :order
254
+ end
255
+ provider(:poise_child) do
256
+ def action_run
257
+ new_resource.order = (node.run_state[:order] += 1)
258
+ end
259
+ end
260
+
261
+ context 'nested' do
262
+ recipe do
263
+ node.run_state[:order] = 0
264
+ poise_grandparent 'one' do
265
+ poise_parent 'two' do
266
+ poise_child 'three'
267
+ end
268
+ end
269
+ end
270
+
271
+ it { is_expected.to run_poise_grandparent('one').with(order: 1) }
272
+ it { is_expected.to run_poise_parent('one::two').with(parent: chef_run.poise_grandparent('one'), order: 2) }
273
+ it { is_expected.to run_poise_child('one::two::three').with(parent: chef_run.poise_parent('one::two'), order: 3) }
274
+ end # /context nested
275
+
276
+ context 'un-nested' do
277
+ recipe do
278
+ node.run_state[:order] = 0
279
+ poise_grandparent 'one'
280
+ poise_parent 'two'
281
+ poise_child 'three'
282
+ end
283
+
284
+ it { is_expected.to run_poise_grandparent('one').with(order: 1) }
285
+ it { is_expected.to run_poise_parent('two').with(parent: chef_run.poise_grandparent('one'), order: 2) }
286
+ it { is_expected.to run_poise_child('three').with(parent: chef_run.poise_parent('two'), order: 3) }
287
+ end # /context un-nested
288
+ end # /describe triple nesting
227
289
  end
@@ -380,5 +380,21 @@ describe Poise::Utils do
380
380
  it { expect { subject }.to_not raise_error }
381
381
  end # /context with 2 arguments
382
382
  end # /context with a negative arity
383
+
384
+ context 'with **' do
385
+ let(:block) do
386
+ proc {|a, **b| nil }
387
+ end
388
+
389
+ context 'with 0 arguments' do
390
+ let(:args) { [] }
391
+ it { expect { subject }.to raise_error ArgumentError, /wrong number of arguments \(0 for 1\+\)/ }
392
+ end # /context with 0 arguments
393
+
394
+ context 'with 1 argument' do
395
+ let(:args) { [1] }
396
+ it { expect { subject }.to_not raise_error }
397
+ end # /context with 1 argument
398
+ end # /context with **
383
399
  end # /describe .check_block_arity!
384
400
  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.3.1
4
+ version: 2.3.2
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-24 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite