halite 1.5.0 → 1.6.0
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 +5 -0
- data/lib/halite/dependencies.rb +10 -4
- data/lib/halite/gem.rb +13 -6
- data/lib/halite/spec_helper.rb +7 -7
- data/lib/halite/spec_helper/patcher.rb +5 -0
- data/lib/halite/version.rb +1 -1
- data/spec/dependencies_spec.rb +19 -0
- data/spec/fixtures/gems/test4/test4.gemspec +1 -0
- data/spec/gem_spec.rb +2 -0
- data/spec/spec_helper_spec.rb +1 -1
- 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: 3bd9453c15ddb7b58021da152d53ee281e00e13e
|
4
|
+
data.tar.gz: 641b09025f131006f0707625a4f22a475deac522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bdb648670ef4bc5afdb954e7c5f769c8bf643f8e58c6065c63211e90e4bfc5336cf358d68313585e53b31e0bad5c70b647c858f2f51d917cb921fbc603e7c19
|
7
|
+
data.tar.gz: 36c524bb699a35b9a7c3f772e56d74cf220cc8e1a41df349dfcb632f52d9a815f0fc515922999457394d54fdc71ff91cc4c3cb097876df0b898301c247899c44
|
data/CHANGELOG.md
CHANGED
data/lib/halite/dependencies.rb
CHANGED
@@ -39,11 +39,17 @@ module Halite
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
# Extract the cookbook dependencies from a gem specification.
|
43
|
+
#
|
44
|
+
# @since 1.6.0 Added development parameter.
|
45
|
+
# @param spec [Gem::Specification] Gem to extract from.
|
46
|
+
# @param development [Boolean] If true, consider development depencies.
|
47
|
+
# @return [Array<Halite::Dependencies::Dependency>]
|
48
|
+
def self.extract(spec, development: false)
|
43
49
|
deps = []
|
44
50
|
deps += clean_and_tag(extract_from_requirements(spec), :requirements)
|
45
51
|
deps += clean_and_tag(extract_from_metadata(spec), :metadata)
|
46
|
-
deps += clean_and_tag(extract_from_dependencies(spec), :dependencies)
|
52
|
+
deps += clean_and_tag(extract_from_dependencies(spec, development: development), :dependencies)
|
47
53
|
deps
|
48
54
|
end
|
49
55
|
|
@@ -58,10 +64,10 @@ module Halite
|
|
58
64
|
spec.metadata.fetch('halite_dependencies', '').split(/,/)
|
59
65
|
end
|
60
66
|
|
61
|
-
def self.extract_from_dependencies(spec)
|
67
|
+
def self.extract_from_dependencies(spec, development: false)
|
62
68
|
# Find any gem dependencies that are cookbooks in disguise.
|
63
69
|
spec.dependencies.select do |dep|
|
64
|
-
dep.type == :runtime && Gem.new(dep).is_halite_cookbook?
|
70
|
+
(development || dep.type == :runtime) && Gem.new(dep).is_halite_cookbook?
|
65
71
|
end.map do |dep|
|
66
72
|
gem = Gem.new(dep)
|
67
73
|
[gem.cookbook_name] + dep.requirements_list + [gem.spec]
|
data/lib/halite/gem.rb
CHANGED
@@ -156,8 +156,8 @@ module Halite
|
|
156
156
|
each_file(spec.require_paths, &block)
|
157
157
|
end
|
158
158
|
|
159
|
-
def cookbook_dependencies
|
160
|
-
|
159
|
+
def cookbook_dependencies(development: false)
|
160
|
+
Dependencies.extract(spec, development: development)
|
161
161
|
end
|
162
162
|
|
163
163
|
# Is this gem really a cookbook? (anything that depends directly on halite and doesn't have the ignore flag)
|
@@ -175,10 +175,17 @@ module Halite
|
|
175
175
|
# Put this in a local variable for a closure below.
|
176
176
|
path = spec.full_gem_path
|
177
177
|
Chef::CookbookVersion.new(cookbook_name, File.join(path, 'chef')).tap do |c|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
178
|
+
# Use CookbookVersion#files_for as a feature test for ManifestV2. This
|
179
|
+
# can be changed to ::Gem::Requirement.create('>= 13').satisfied_by?(::Gem::Version.create(Chef::VERSION))
|
180
|
+
# once https://github.com/chef/chef/pull/5929 is merged.
|
181
|
+
if defined?(c.files_for)
|
182
|
+
c.all_files = each_file('chef').map(&:first)
|
183
|
+
else
|
184
|
+
c.attribute_filenames = each_file('chef/attributes').map(&:first)
|
185
|
+
c.file_filenames = each_file('chef/files').map(&:first)
|
186
|
+
c.recipe_filenames = each_file('chef/recipes').map(&:first)
|
187
|
+
c.template_filenames = each_file('chef/templates').map(&:first)
|
188
|
+
end
|
182
189
|
# Haxx, rewire the filevendor for this cookbook to look up in our folder.
|
183
190
|
# This is touching two different internal interfaces, but ¯\_(ツ)_/¯
|
184
191
|
c.send(:file_vendor).define_singleton_method(:get_filename) do |filename|
|
data/lib/halite/spec_helper.rb
CHANGED
@@ -264,7 +264,7 @@ module Halite
|
|
264
264
|
# end
|
265
265
|
# it { is_expected.to run_my_resource('test').with(path: '/tmp') }
|
266
266
|
# end
|
267
|
-
def resource(name, auto: true, parent: Chef::Resource, step_into: true, unwrap_notifying_block: true, defined_at: caller[0], &block)
|
267
|
+
def resource(name, auto: true, parent: Chef::Resource, step_into: true, unwrap_notifying_block: true, patch: true, defined_at: caller[0], &block)
|
268
268
|
parent = resources[parent] if parent.is_a?(Symbol)
|
269
269
|
raise Halite::Error.new("Parent class for #{name} is not a class: #{parent.inspect}") unless parent.is_a?(Class)
|
270
270
|
# Pull out the example group for use in the class.
|
@@ -320,7 +320,7 @@ module Halite
|
|
320
320
|
end
|
321
321
|
|
322
322
|
# Clean up any global registration that happens on class compile.
|
323
|
-
Patcher.post_create_cleanup(name, resource_class)
|
323
|
+
Patcher.post_create_cleanup(name, resource_class) if patch
|
324
324
|
|
325
325
|
# Store for use up with the parent system
|
326
326
|
halite_helpers[:resources][name.to_sym] = resource_class
|
@@ -329,7 +329,7 @@ module Halite
|
|
329
329
|
step_into(resource_class, name, unwrap_notifying_block: unwrap_notifying_block) if step_into
|
330
330
|
|
331
331
|
around do |ex|
|
332
|
-
if resource(name) == resource_class
|
332
|
+
if patch && resource(name) == resource_class
|
333
333
|
# We haven't been overridden from a nested scope.
|
334
334
|
Patcher.patch(name, resource_class, Chef::Resource) { ex.run }
|
335
335
|
else
|
@@ -367,9 +367,9 @@ module Halite
|
|
367
367
|
# it { is_expected.to run_my_resource('test') }
|
368
368
|
# it { is_expected.to run_ruby_block('test') }
|
369
369
|
# end
|
370
|
-
def provider(name, auto: true, rspec: true, parent: Chef::Provider, defined_at: caller[0], &block)
|
370
|
+
def provider(name, auto: true, rspec: true, parent: Chef::Provider, patch: true, defined_at: caller[0], &block)
|
371
371
|
parent = providers[parent] if parent.is_a?(Symbol)
|
372
|
-
raise Halite::Error.new("Parent class for #{name} is not a class: #{
|
372
|
+
raise Halite::Error.new("Parent class for #{name} is not a class: #{parent.inspect}") unless parent.is_a?(Class)
|
373
373
|
# Pull out the example group for use in the class.
|
374
374
|
example_group = self
|
375
375
|
# Create the provider class.
|
@@ -414,13 +414,13 @@ module Halite
|
|
414
414
|
end
|
415
415
|
|
416
416
|
# Clean up any global registration that happens on class compile.
|
417
|
-
Patcher.post_create_cleanup(name, provider_class)
|
417
|
+
Patcher.post_create_cleanup(name, provider_class) if patch
|
418
418
|
|
419
419
|
# Store for use up with the parent system
|
420
420
|
halite_helpers[:providers][name.to_sym] = provider_class
|
421
421
|
|
422
422
|
around do |ex|
|
423
|
-
if provider(name) == provider_class
|
423
|
+
if patch && provider(name) == provider_class
|
424
424
|
# We haven't been overridden from a nested scope.
|
425
425
|
Patcher.patch(name, provider_class, Chef::Provider) { ex.run }
|
426
426
|
else
|
@@ -15,6 +15,7 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
require 'chef/resource'
|
18
|
+
require 'chef/version'
|
18
19
|
|
19
20
|
|
20
21
|
module Halite
|
@@ -25,6 +26,9 @@ module Halite
|
|
25
26
|
# @since 1.0.0
|
26
27
|
# @api private
|
27
28
|
module Patcher
|
29
|
+
# Flag to disable module-name patching.
|
30
|
+
DISABLE_PATCH_MODULE = ::Gem::Requirement.create('>= 13').satisfied_by?(::Gem::Version.create(Chef::VERSION))
|
31
|
+
|
28
32
|
# Patch a class in to Chef for the duration of a block.
|
29
33
|
#
|
30
34
|
# @param name [String, Symbol] Name to create in snake-case (eg. :my_name).
|
@@ -90,6 +94,7 @@ module Halite
|
|
90
94
|
# @param block [Proc] Block to execute while the name is available.
|
91
95
|
# @return [void]
|
92
96
|
def self.patch_module(mod, name, obj, &block)
|
97
|
+
return block.call if DISABLE_PATCH_MODULE
|
93
98
|
class_name = Chef::Mixin::ConvertToClassName.convert_to_class_name(name.to_s)
|
94
99
|
if mod.const_defined?(class_name, false)
|
95
100
|
old_class = mod.const_get(class_name, false)
|
data/lib/halite/version.rb
CHANGED
data/spec/dependencies_spec.rb
CHANGED
@@ -98,6 +98,25 @@ describe Halite::Dependencies do
|
|
98
98
|
let(:gemspec) { fake_gem {|s| s.add_development_dependency 'gem1' } }
|
99
99
|
it { is_expected.to eq [] }
|
100
100
|
end
|
101
|
+
|
102
|
+
context 'with development mode' do
|
103
|
+
subject { described_class.extract_from_dependencies(gemspec, development: true) }
|
104
|
+
|
105
|
+
context 'with a halite-ish dependency' do
|
106
|
+
let(:gemspec) { fake_gem {|s| s.add_dependency 'gem3' } }
|
107
|
+
it { is_expected.to eq [['gem3', '>= 0', gem_stubs[2]]] }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with a development dependency' do
|
111
|
+
let(:gemspec) { fake_gem {|s| s.add_development_dependency 'gem3' } }
|
112
|
+
it { is_expected.to eq [['gem3', '>= 0', gem_stubs[2]]] }
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'with a non-halite dependency' do
|
116
|
+
let(:gemspec) { fake_gem {|s| s.add_development_dependency 'gem1' } }
|
117
|
+
it { is_expected.to eq [] }
|
118
|
+
end
|
119
|
+
end # /context with development mode
|
101
120
|
end # /describe #extract_from_dependencies
|
102
121
|
|
103
122
|
describe '#clean' do
|
data/spec/gem_spec.rb
CHANGED
@@ -147,6 +147,8 @@ describe Halite::Gem do
|
|
147
147
|
context 'when loading test4' do
|
148
148
|
let(:gem_name) { 'test4' }
|
149
149
|
its(:cookbook_name) { is_expected.to eq 'test4' }
|
150
|
+
its(:cookbook_dependencies) { is_expected.to eq [] }
|
151
|
+
it { expect(subject.cookbook_dependencies(development: true)).to eq [Halite::Dependencies::Dependency.new('test2', '~> 4.5.6', :dependencies)] }
|
150
152
|
its(:version) { is_expected.to eq '2.3.1.rc.1' }
|
151
153
|
its(:cookbook_version) { is_expected.to eq '2.3.1' }
|
152
154
|
its(:issues_url) { is_expected.to eq 'http://issues' }
|
data/spec/spec_helper_spec.rb
CHANGED
@@ -87,7 +87,7 @@ describe Halite::SpecHelper do
|
|
87
87
|
resource(:halite_test, parent: :halite_parent)
|
88
88
|
it { is_expected.to be_a(Class) }
|
89
89
|
it { is_expected.to be < Chef::Resource }
|
90
|
-
it { is_expected.to be <
|
90
|
+
it { is_expected.to be < resource('halite_parent') }
|
91
91
|
its(:resource_name) { is_expected.to eq :halite_test } if defined?(Chef::Resource.resource_name)
|
92
92
|
it { expect(subject.new(nil, nil).resource_name).to eq(:halite_test) }
|
93
93
|
end # /context with a helper-defined parent
|
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.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Kantrowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.6.
|
244
|
+
rubygems_version: 2.6.11
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: A set of helpers to write Chef cookbooks as Ruby gems.
|