halite 1.0.3 → 1.0.4
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/lib/halite/spec_helper.rb +4 -4
- data/lib/halite/spec_helper/patcher.rb +91 -8
- data/lib/halite/version.rb +1 -1
- data/spec/spec_helper_spec.rb +7 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 759f66650fe2e7a304845bd62730aa796c81b4ac
|
4
|
+
data.tar.gz: bc405024358044f1532672757e589a7f204715c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370b0aa318e442112bcfb0e80249aebd484325e38aadc3b0a079d5f2517d540c1fbdf235693672bfb931b6a988511b5c820a246ede47499c1713c08427229321
|
7
|
+
data.tar.gz: d9d42a3c5ccfd23d2dbf4ae361ff64573c125ddd35810ce5a73cd40e7af023bd45bdf06962af3ebe1eba149546f61c996c573a920fcfc047604b080ec5c31944
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.0.4
|
4
|
+
|
5
|
+
* Fixes to work with Chef 12.4.
|
6
|
+
|
7
|
+
## v1.0.3
|
8
|
+
|
9
|
+
* Never try to do universe installs of pre-release gems in the Berkshelf extension.
|
10
|
+
|
3
11
|
## v1.0.2
|
4
12
|
|
5
13
|
* Handle converting cookbooks with pre-release version numbers and other
|
data/lib/halite/spec_helper.rb
CHANGED
@@ -302,8 +302,8 @@ module Halite
|
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
|
-
#
|
306
|
-
|
305
|
+
# Clean up any global registration that happens on class compile.
|
306
|
+
Patcher.post_create_cleanup(name, resource_class)
|
307
307
|
|
308
308
|
# Store for use up with the parent system
|
309
309
|
halite_helpers[:resources][name.to_sym] = resource_class
|
@@ -393,8 +393,8 @@ module Halite
|
|
393
393
|
class_exec(&block) if block
|
394
394
|
end
|
395
395
|
|
396
|
-
#
|
397
|
-
|
396
|
+
# Clean up any global registration that happens on class compile.
|
397
|
+
Patcher.post_create_cleanup(name, provider_class)
|
398
398
|
|
399
399
|
# Store for use up with the parent system
|
400
400
|
halite_helpers[:providers][name.to_sym] = provider_class
|
@@ -35,17 +35,41 @@ module Halite
|
|
35
35
|
def self.patch(name, klass, mod=nil, &block)
|
36
36
|
patch_descendants_tracker(klass) do
|
37
37
|
patch_node_map(name, klass) do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
51
|
+
# Perform any post-class-creation cleanup tasks to deal with compile time
|
52
|
+
# global registrations.
|
53
|
+
#
|
54
|
+
# @since 1.0.4
|
55
|
+
# @param name [String, Symbol] Name of the class that was created in
|
56
|
+
# snake-case (eg. :my_name).
|
57
|
+
# @param klass [Class] Newly created class.
|
58
|
+
# @return [void]
|
59
|
+
def self.post_create_cleanup(name, klass)
|
60
|
+
# Remove from DescendantsTracker.
|
61
|
+
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)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
49
73
|
# Patch an object in to a global namespace for the duration of a block.
|
50
74
|
#
|
51
75
|
# @param mod [Module] Namespace to patch in to.
|
@@ -91,20 +115,20 @@ module Halite
|
|
91
115
|
end
|
92
116
|
end
|
93
117
|
|
94
|
-
# Patch a class in to its node_map.
|
118
|
+
# Patch a class in to its node_map. This is not used in 12.4+.
|
95
119
|
#
|
96
120
|
# @param name [Symbol] Name to patch in.
|
97
121
|
# @param klass [Class] Resource class to patch in.
|
98
122
|
# @param block [Proc] Block to execute while the patch is available.
|
99
123
|
# @return [void]
|
100
124
|
def self.patch_node_map(name, klass, &block)
|
125
|
+
return block.call unless defined?(klass.node_map)
|
101
126
|
begin
|
102
127
|
# Technically this is set to true on >=12.4, but this should work.
|
103
128
|
klass.node_map.set(name, klass)
|
104
129
|
block.call
|
105
130
|
ensure
|
106
|
-
|
107
|
-
klass.node_map.instance_variable_get(:@map).delete(name)
|
131
|
+
remove_from_node_map(klass.node_map, klass)
|
108
132
|
end
|
109
133
|
end
|
110
134
|
|
@@ -125,6 +149,65 @@ module Halite
|
|
125
149
|
end
|
126
150
|
end
|
127
151
|
|
152
|
+
# Patch a class in to the correct priority map for the duration of a code
|
153
|
+
# block. This is a no-op before Chef 12.4.
|
154
|
+
#
|
155
|
+
# @since 1.0.4
|
156
|
+
# @param name [Symbol] Name to patch in.
|
157
|
+
# @param klass [Class] Resource or provider class to patch in.
|
158
|
+
# @param block [Proc] Block to execute while the patch is available.
|
159
|
+
# @return [void]
|
160
|
+
def self.patch_priority_map(name, klass, &block)
|
161
|
+
priority_map = priority_map_for(klass)
|
162
|
+
return block.call unless priority_map
|
163
|
+
begin
|
164
|
+
# Unlike patch_node_map, this has to be an array!
|
165
|
+
klass.instance_variable_get(:@halite_original_priority_keys).each do |key|
|
166
|
+
priority_map.set(key, [klass])
|
167
|
+
end
|
168
|
+
block.call
|
169
|
+
ensure
|
170
|
+
remove_from_node_map(priority_map, klass)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
# Find the global priority map for a class.
|
177
|
+
#
|
178
|
+
# @since 1.0.4
|
179
|
+
# @param klass [Class] Resource or provider class to look up.
|
180
|
+
# @return [nil, Chef::Platform::ResourcePriorityMap, Chef::Platform::ProviderPriorityMap]
|
181
|
+
def self.priority_map_for(klass)
|
182
|
+
if defined?(Chef.resource_priority_map) && klass < Chef::Resource
|
183
|
+
Chef.resource_priority_map
|
184
|
+
elsif defined?(Chef.provider_priority_map) && klass < Chef::Provider
|
185
|
+
Chef.provider_priority_map
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Remove a value from a Chef::NodeMap. Returns the keys that were removed.
|
190
|
+
#
|
191
|
+
# @since 1.0.4
|
192
|
+
# @param node_map [Chef::NodeMap] Node map to remove from.
|
193
|
+
# @param value [Object] Value to remove.
|
194
|
+
# @return [Array<Symbol>]
|
195
|
+
def self.remove_from_node_map(node_map, value)
|
196
|
+
# Sigh.
|
197
|
+
removed_keys = []
|
198
|
+
node_map.instance_variable_get(:@map).each do |key, matchers|
|
199
|
+
matchers.delete_if do |matcher|
|
200
|
+
# In 12.4+ this value is an array of classes, before that it is the class.
|
201
|
+
if matcher[:value].is_a?(Array)
|
202
|
+
matcher[:value].include?(value)
|
203
|
+
else
|
204
|
+
matcher[:value] == value
|
205
|
+
end && removed_keys << key # Track removed keys in a hacky way.
|
206
|
+
end
|
207
|
+
end
|
208
|
+
removed_keys
|
209
|
+
end
|
210
|
+
|
128
211
|
end
|
129
212
|
end
|
130
213
|
end
|
data/lib/halite/version.rb
CHANGED
data/spec/spec_helper_spec.rb
CHANGED
@@ -66,7 +66,8 @@ describe Halite::SpecHelper do
|
|
66
66
|
resource(:halite_test, auto: false)
|
67
67
|
it { is_expected.to be_a(Class) }
|
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
|
+
it { expect(subject.new(nil, nil).resource_name).to be_nil } unless defined?(Chef::Resource.resource_name)
|
70
71
|
it { expect(subject.new(nil, nil).action).to eq(:nothing) }
|
71
72
|
it { expect(subject.new(nil, nil).allowed_actions).to eq([:nothing]) }
|
72
73
|
end # /context with auto:false
|
@@ -193,7 +194,7 @@ describe Halite::SpecHelper do
|
|
193
194
|
provider(:halite_test_help)
|
194
195
|
|
195
196
|
context 'helper-created resource' do
|
196
|
-
resource(:halite_test_helper, step_into:false)
|
197
|
+
resource(:halite_test_helper, step_into: false)
|
197
198
|
recipe do
|
198
199
|
halite_test_helper 'test'
|
199
200
|
end
|
@@ -201,7 +202,7 @@ describe Halite::SpecHelper do
|
|
201
202
|
end # /context helper-created resource
|
202
203
|
|
203
204
|
context 'helper-created resource with Poise' do
|
204
|
-
resource(:halite_test_helper_poise, step_into:false) do
|
205
|
+
resource(:halite_test_helper_poise, step_into: false) do
|
205
206
|
include Poise
|
206
207
|
provides(:halite_test_helper_poise)
|
207
208
|
end
|
@@ -213,7 +214,8 @@ describe Halite::SpecHelper do
|
|
213
214
|
end # describe without step-into there should be no ChefSpec resource-level matcher
|
214
215
|
end # /describe #step_into
|
215
216
|
|
216
|
-
describe '
|
217
|
+
describe 'patcher' do
|
218
|
+
#let(:chefspec_options) { {log_level: :debug} }
|
217
219
|
resource(:halite_test)
|
218
220
|
subject { resource(:halite_test).new('test', chef_run.run_context).provider_for_action(:run) }
|
219
221
|
|
@@ -234,5 +236,5 @@ describe Halite::SpecHelper do
|
|
234
236
|
context 'without a provider in scope' do
|
235
237
|
it { expect { subject }.to raise_error ArgumentError }
|
236
238
|
end # /context without a provider in scope
|
237
|
-
end # /describe
|
239
|
+
end # /describe patcher
|
238
240
|
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.
|
4
|
+
version: 1.0.4
|
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-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
requirements: []
|
229
229
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.4.
|
230
|
+
rubygems_version: 2.4.8
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: A set of helpers to write Chef cookbooks as Ruby gems.
|