halite 1.0.6 → 1.0.7

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: 19ac06d0b44405d953ee4542a9193dbcbd9dddf6
4
- data.tar.gz: 034f1aa01e6565741aba6bdc7619a4c10d8482ab
3
+ metadata.gz: 17db882da6b0bae3c6e9ce2b831d14ae2c5807c7
4
+ data.tar.gz: 5a0968925d77b2d5c18e2185aa1fa82bdd21adda
5
5
  SHA512:
6
- metadata.gz: 8ecbf84b21b7d588bfcaf900a7bd0e5c3cc00b79974d34a1ceb070263ee55a84c569a67f563002fc1e2e4218dd73acaed44756c453b384163f9e8e8e7ffdcf87
7
- data.tar.gz: be2fe0c44b6cd7bf6ad4674f7b06d8398bac9fa1c7700453ff20323779f6dba0908eceb6c5dd5466233f090c21f808816e900ae9ba9db310a413a934b1656437
6
+ metadata.gz: 6262b355b9183ebb3d365a98dd477d6dba0235226bbf7aa48023b560c7c9afe670149cff67517f4933be6cef47549c07bf99b41dcd44e28a843b4bfce24d906c
7
+ data.tar.gz: 46d28077eac059e3137dbf792e6fa5ccbc00751ae17d65f6f8dd976eb20ce4b22726683fc9e96a2beaa235d424f45ea692f2ae154d7c2b8bf5322623c3f04598
data/.travis.yml CHANGED
@@ -10,7 +10,12 @@ rvm:
10
10
  - "2.1"
11
11
  - "2.2"
12
12
  gemfile:
13
- - gemfiles/default.gemfile
13
+ - gemfiles/chef-12.0.gemfile
14
+ - gemfiles/chef-12.1.gemfile
15
+ - gemfiles/chef-12.2.gemfile
16
+ - gemfiles/chef-12.3.gemfile
17
+ - gemfiles/chef-12.4.0.gemfile
18
+ - gemfiles/chef-12.gemfile
14
19
  - gemfiles/master.gemfile
15
20
  env:
16
21
  global:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.7
4
+
5
+ * More fixes for Chef 12.4.1.
6
+
3
7
  ## v1.0.6
4
8
 
5
9
  * Minor fix for forward compatibility with 12.4.1+ and the spec helper's auto mode.
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.0.0'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.1.0'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.2.0'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.3.0'
@@ -15,3 +15,5 @@
15
15
  #
16
16
 
17
17
  eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '12.4.0'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.0'
@@ -302,6 +302,11 @@ module Halite
302
302
  end
303
303
  end
304
304
 
305
+ # Try to set the resource name for 12.4+.
306
+ if defined?(resource_class.resource_name)
307
+ resource_class.resource_name(name)
308
+ end
309
+
305
310
  # Clean up any global registration that happens on class compile.
306
311
  Patcher.post_create_cleanup(name, resource_class)
307
312
 
@@ -36,11 +36,13 @@ module Halite
36
36
  patch_descendants_tracker(klass) do
37
37
  patch_node_map(name, klass) do
38
38
  patch_priority_map(name, klass) do
39
- patch_recipe_dsl(name, klass) do
40
- if mod
41
- patch_module(mod, name, klass, &block)
42
- else
43
- block.call
39
+ patch_handler_map(name, klass) do
40
+ patch_recipe_dsl(name, klass) do
41
+ if mod
42
+ patch_module(mod, name, klass, &block)
43
+ else
44
+ block.call
45
+ end
44
46
  end
45
47
  end
46
48
  end
@@ -59,14 +61,16 @@ module Halite
59
61
  def self.post_create_cleanup(name, klass)
60
62
  # Remove from DescendantsTracker.
61
63
  Chef::Mixin::DescendantsTracker.direct_descendants(klass.superclass).delete(klass)
62
- # Remove from the priority maps.
63
- if priority_map = priority_map_for(klass)
64
- # Make sure we add name in there too because anonymous classes don't
65
- # get a priority map registration by default.
66
- removed_keys = remove_from_node_map(priority_map, klass) | [name.to_sym]
67
- # This ivar is used down in #patch_priority_map to re-add the correct
68
- # keys based on the class definition.
69
- klass.instance_variable_set(:@halite_original_priority_keys, removed_keys)
64
+ # Remove from the priority and handler maps.
65
+ {priority: priority_map_for(klass), handler: handler_map_for(klass)}.each do |type, map|
66
+ if map
67
+ # Make sure we add name in there too because anonymous classes don't
68
+ # get a handler map registration by default.
69
+ removed_keys = remove_from_node_map(map, klass) | [name.to_sym]
70
+ # This ivar is used down in #patch_*_map to re-add the correct
71
+ # keys based on the class definition.
72
+ klass.instance_variable_set(:"@halite_original_#{type}_keys", removed_keys)
73
+ end
70
74
  end
71
75
  # Remove from the global node map.
72
76
  if defined?(Chef::Resource.node_map)
@@ -180,6 +184,27 @@ module Halite
180
184
  end
181
185
  end
182
186
 
187
+ # Patch a class in to the correct handler map for the duration of a code
188
+ # block. This is a no-op before Chef 12.4.1.
189
+ #
190
+ # @since 1.0.7
191
+ # @param name [Symbol] Name to patch in.
192
+ # @param klass [Class] Resource or provider class to patch in.
193
+ # @param block [Proc] Block to execute while the patch is available.
194
+ # @return [void]
195
+ def self.patch_handler_map(name, klass, &block)
196
+ handler_map = handler_map_for(klass)
197
+ return block.call unless handler_map
198
+ begin
199
+ klass.instance_variable_get(:@halite_original_handler_keys).each do |key|
200
+ handler_map.set(key, klass)
201
+ end
202
+ block.call
203
+ ensure
204
+ remove_from_node_map(handler_map, klass)
205
+ end
206
+ end
207
+
183
208
  private
184
209
 
185
210
  # Find the global priority map for a class.
@@ -195,6 +220,19 @@ module Halite
195
220
  end
196
221
  end
197
222
 
223
+ # Find the global handler map for a class.
224
+ #
225
+ # @since 1.0.7
226
+ # @param klass [Class] Resource or provider class to look up.
227
+ # @return [nil, Chef::Platform::ResourceHandlerMap, Chef::Platform::ProviderHandlerMap]
228
+ def self.handler_map_for(klass)
229
+ if defined?(Chef.resource_handler_map) && klass < Chef::Resource
230
+ Chef.resource_handler_map
231
+ elsif defined?(Chef.provider_handler_map) && klass < Chef::Provider
232
+ Chef.provider_handler_map
233
+ end
234
+ end
235
+
198
236
  # Remove a value from a Chef::NodeMap. Returns the keys that were removed.
199
237
  #
200
238
  # @since 1.0.4
@@ -204,7 +242,13 @@ module Halite
204
242
  def self.remove_from_node_map(node_map, value)
205
243
  # Sigh.
206
244
  removed_keys = []
207
- node_map.instance_variable_get(:@map).each do |key, matchers|
245
+ # 12.4.1+ switched this to a private accessor and lazy init.
246
+ map = if node_map.respond_to?(:map, true)
247
+ node_map.send(:map)
248
+ else
249
+ node_map.instance_variable_get(:@map)
250
+ end
251
+ map.each do |key, matchers|
208
252
  matchers.delete_if do |matcher|
209
253
  # In 12.4+ this value is an array of classes, before that it is the class.
210
254
  if matcher[:value].is_a?(Array)
@@ -213,6 +257,8 @@ module Halite
213
257
  matcher[:value] == value
214
258
  end && removed_keys << key # Track removed keys in a hacky way.
215
259
  end
260
+ # Clear empty matchers entirely.
261
+ map.delete(key) if matchers.empty?
216
262
  end
217
263
  removed_keys
218
264
  end
@@ -17,5 +17,5 @@
17
17
 
18
18
  module Halite
19
19
  # Halite version.
20
- VERSION = '1.0.6'
20
+ VERSION = '1.0.7'
21
21
  end
@@ -68,8 +68,8 @@ describe Halite::SpecHelper do
68
68
  it { is_expected.to be < Chef::Resource }
69
69
  # #resource_name was added upstream in 12.4 so ignore this test there.
70
70
  it { expect(subject.new(nil, nil).resource_name).to be_nil } unless defined?(Chef::Resource.resource_name)
71
- it { expect(subject.new(nil, nil).action).to eq(:nothing) }
72
- it { expect(subject.new(nil, nil).allowed_actions).to eq([:nothing]) }
71
+ it { expect(Array(subject.new(nil, nil).action)).to eq [:nothing] }
72
+ it { expect(subject.new(nil, nil).allowed_actions).to eq [:nothing] }
73
73
  end # /context with auto:false
74
74
 
75
75
  context 'with a parent' do
@@ -104,6 +104,7 @@ describe Halite::SpecHelper do
104
104
  :parent
105
105
  end
106
106
  end
107
+ subject { resource(:halite_test).new(nil, nil).value }
107
108
 
108
109
  context 'sibling' do
109
110
  resource(:halite_parent) do
@@ -111,11 +112,14 @@ describe Halite::SpecHelper do
111
112
  :sibling
112
113
  end
113
114
  end
115
+ # Sanity check that this still works. Important test is below.
116
+ resource(:halite_test, parent: :halite_parent)
117
+ it { is_expected.to eq(:sibling) }
114
118
  end
115
119
 
116
120
  context 'inner' do
121
+ # The actual regression test.
117
122
  resource(:halite_test, parent: :halite_parent)
118
- subject { resource(:halite_test).new(nil, nil).value }
119
123
  it { is_expected.to eq(:parent) }
120
124
  end
121
125
  end # /context regression test for finding the wrong parent in a sibling context
@@ -234,7 +238,8 @@ describe Halite::SpecHelper do
234
238
  end # /context with a named provider in scope
235
239
 
236
240
  context 'without a provider in scope' do
237
- it { expect { subject }.to raise_error ArgumentError }
241
+ # 12.4.1+ uses Chef::Exceptions::ProviderNotFound, before that ArgumentError.
242
+ it { expect { subject }.to raise_error (defined?(Chef::Exceptions::ProviderNotFound) ? Chef::Exceptions::ProviderNotFound : ArgumentError) }
238
243
  end # /context without a provider in scope
239
244
  end # /describe patcher
240
245
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -130,7 +130,12 @@ files:
130
130
  - LICENSE
131
131
  - README.md
132
132
  - Rakefile
133
- - gemfiles/default.gemfile
133
+ - gemfiles/chef-12.0.gemfile
134
+ - gemfiles/chef-12.1.gemfile
135
+ - gemfiles/chef-12.2.gemfile
136
+ - gemfiles/chef-12.3.gemfile
137
+ - gemfiles/chef-12.4.0.gemfile
138
+ - gemfiles/chef-12.gemfile
134
139
  - gemfiles/master.gemfile
135
140
  - halite.gemspec
136
141
  - lib/berkshelf/halite.rb