halite 1.0.0.rc.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +14 -4
- data/.yardopts +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +30 -8
- data/LICENSE +202 -202
- data/README.md +104 -2
- data/Rakefile +25 -5
- data/gemfiles/default.gemfile +17 -0
- data/gemfiles/master.gemfile +21 -0
- data/halite.gemspec +21 -10
- data/lib/berkshelf/halite.rb +25 -0
- data/lib/berkshelf/locations/gem.rb +84 -0
- data/lib/halite.rb +34 -4
- data/lib/halite/berkshelf/helper.rb +8 -2
- data/lib/halite/berkshelf/source.rb +9 -1
- data/lib/halite/converter.rb +34 -10
- data/lib/halite/converter/chef.rb +43 -0
- data/lib/halite/converter/libraries.rb +93 -26
- data/lib/halite/converter/metadata.rb +48 -10
- data/lib/halite/converter/misc.rb +43 -0
- data/lib/halite/dependencies.rb +48 -8
- data/lib/halite/error.rb +20 -0
- data/lib/halite/gem.rb +106 -21
- data/lib/halite/helper_base.rb +129 -0
- data/lib/halite/rake_helper.rb +46 -60
- data/lib/halite/rake_tasks.rb +17 -1
- data/lib/halite/spec_helper.rb +403 -54
- data/lib/halite/spec_helper/patcher.rb +130 -0
- data/lib/halite/spec_helper/runner.rb +57 -9
- data/lib/halite/version.rb +19 -1
- data/spec/converter/chef_spec.rb +54 -0
- data/spec/converter/libraries_spec.rb +131 -123
- data/spec/converter/metadata_spec.rb +61 -8
- data/spec/converter/misc_spec.rb +61 -0
- data/spec/converter_spec.rb +21 -6
- data/spec/dependencies_spec.rb +64 -10
- data/spec/example_resources/poise.rb +42 -0
- data/spec/example_resources/simple.rb +48 -0
- data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1.rb +0 -0
- data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1/version.rb +0 -0
- data/spec/fixtures/cookbooks/test1/libraries/default.rb +4 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test1/metadata.rb +0 -0
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/attributes.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/resource.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/version.rb +0 -0
- data/spec/fixtures/cookbooks/test2/libraries/default.rb +3 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test2/metadata.rb +1 -1
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/recipes/default.rb +0 -0
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/templates/default/conf.erb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3.rb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/dsl.rb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/version.rb +0 -0
- data/spec/fixtures/cookbooks/test3/libraries/default.rb +4 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test3/metadata.rb +0 -0
- data/spec/{data/gems/test3/chef → fixtures/cookbooks/test3}/recipes/default.rb +0 -0
- data/spec/{data → fixtures}/gems/test1/Rakefile +0 -0
- data/spec/fixtures/gems/test1/lib/test1.rb +2 -0
- data/spec/fixtures/gems/test1/lib/test1/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test1/test1.gemspec +0 -0
- data/spec/{data → fixtures}/gems/test2/Rakefile +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/attributes.rb +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/recipes/default.rb +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/templates/default/conf.erb +0 -0
- data/spec/fixtures/gems/test2/lib/test2.rb +4 -0
- data/spec/{data/integration_cookbooks/test2/libraries/test2__resource.rb → fixtures/gems/test2/lib/test2/resource.rb} +1 -2
- data/spec/fixtures/gems/test2/lib/test2/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test2/test2.gemspec +0 -0
- data/spec/{data → fixtures}/gems/test3/Rakefile +0 -0
- data/spec/{data/integration_cookbooks/test3 → fixtures/gems/test3/chef}/recipes/default.rb +0 -0
- data/spec/fixtures/gems/test3/lib/test3.rb +4 -0
- data/spec/{data/integration_cookbooks/test3/libraries/test3__dsl.rb → fixtures/gems/test3/lib/test3/dsl.rb} +1 -2
- data/spec/fixtures/gems/test3/lib/test3/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test3/test3.gemspec +1 -0
- data/spec/gem_spec.rb +41 -31
- data/spec/integration_spec.rb +58 -82
- data/spec/runner_spec.rb +108 -0
- data/spec/spec_helper.rb +19 -26
- data/spec/spec_helper_spec.rb +238 -0
- metadata +124 -151
- data/lib/halite/converter/other.rb +0 -19
- data/lib/halite/converter/readme.rb +0 -20
- data/spec/converter/other_spec.rb +0 -56
- data/spec/converter/readme_spec.rb +0 -55
- data/spec/data/integration_cookbooks/test1/libraries/test1.rb +0 -3
- data/spec/data/integration_cookbooks/test1/libraries/test1__version.rb +0 -4
- data/spec/data/integration_cookbooks/test2/libraries/test2.rb +0 -5
- data/spec/data/integration_cookbooks/test2/libraries/test2__version.rb +0 -4
- data/spec/data/integration_cookbooks/test3/libraries/test3.rb +0 -5
- data/spec/data/integration_cookbooks/test3/libraries/test3__version.rb +0 -4
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://img.shields.io/travis/coderanger/halite.svg)](https://travis-ci.org/coderanger/halite)
|
4
4
|
[![Gem Version](https://img.shields.io/gem/v/halite.svg)](https://rubygems.org/gems/halite)
|
5
|
-
[![
|
6
|
-
[![
|
5
|
+
[![Coverage](https://img.shields.io/codecov/c/github/coderanger/halite.svg)](https://codecov.io/github/coderanger/halite)
|
6
|
+
[![Gemnasium](https://img.shields.io/gemnasium/coderanger/halite.svg)](https://gemnasium.com/coderanger/halite)
|
7
7
|
[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
|
8
8
|
|
9
9
|
Write as a gem, release as a cookbook.
|
@@ -18,6 +18,15 @@ All Ruby code in the gem will be converted in to `libraries/` files. You can
|
|
18
18
|
add cookbook-specific files by add them to a `chef/` folder in the root of the
|
19
19
|
gem.
|
20
20
|
|
21
|
+
## Why?
|
22
|
+
|
23
|
+
Developing cookbooks as gems allows using the full Ruby development ecosystem
|
24
|
+
and tooling more directly. This includes things like Simplecov for coverage
|
25
|
+
testing, YARD for documentation, and Gemnasium for dependency monitoring. For
|
26
|
+
a cookbook that is already mostly library files, this is a natural transition,
|
27
|
+
with few cookbook-specific pieces to start with. This also allows using Bundler
|
28
|
+
to manage versions instead of Berkshelf.
|
29
|
+
|
21
30
|
## Cookbook Dependencies
|
22
31
|
|
23
32
|
To add cookbook dependencies either add them to the gem requirements or use
|
@@ -73,3 +82,96 @@ To activate it, include the extension in your `Berksfile`:
|
|
73
82
|
```ruby
|
74
83
|
extension 'halite'
|
75
84
|
```
|
85
|
+
|
86
|
+
## Spec Helper
|
87
|
+
|
88
|
+
Halite includes a set of helpers for RSpec tests. You can enable them in your
|
89
|
+
`spec_helper.rb`:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'halite/spec_helper'
|
93
|
+
|
94
|
+
RSpec.configure do |config|
|
95
|
+
config.include Halite::SpecHelper
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
### `recipe`
|
100
|
+
|
101
|
+
Recipes to converge for the test can be defined inline on example groups:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
describe 'cookbook recipe' do
|
105
|
+
recipe 'myrecipe'
|
106
|
+
it { is_expected.to create_file('/myfile') }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'inline recipe' do
|
110
|
+
recipe do
|
111
|
+
file '/myfile' do
|
112
|
+
content 'mycontent'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
it { is_expected.to create_file('/myfile') }
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
### `step_into`
|
120
|
+
|
121
|
+
A resource can be added to the list to step in to via the `step_into` helper:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
describe 'mycookbook' do
|
125
|
+
recipe 'mycookbook::server'
|
126
|
+
step_into :mycookbook_lwrp
|
127
|
+
it { is_expected.to ... }
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
### `resource` and `provider`
|
132
|
+
|
133
|
+
For testing mixin-based cookbooks, new resource and provider classes can be
|
134
|
+
declared on an example group:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
describe MyMixin do
|
138
|
+
resource(:test_resource) do
|
139
|
+
include MyMixin
|
140
|
+
def foo(val=nil)
|
141
|
+
set_or_return(:foo, val, {})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
provider(:test_resource) do
|
145
|
+
def action_run
|
146
|
+
# ...
|
147
|
+
end
|
148
|
+
end
|
149
|
+
recipe do
|
150
|
+
test_resource 'test' do
|
151
|
+
foo 1
|
152
|
+
action :run
|
153
|
+
end
|
154
|
+
end
|
155
|
+
it { is_expected.to ... }
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
These helper resources and providers are only available within the scope of
|
160
|
+
recipes defined on that example group or groups nested inside it. Helper
|
161
|
+
resources are automatically `step_into`'d.
|
162
|
+
|
163
|
+
## License
|
164
|
+
|
165
|
+
Copyright 2015, Noah Kantrowitz
|
166
|
+
|
167
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
168
|
+
you may not use this file except in compliance with the License.
|
169
|
+
You may obtain a copy of the License at
|
170
|
+
|
171
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
172
|
+
|
173
|
+
Unless required by applicable law or agreed to in writing, software
|
174
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
175
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
176
|
+
See the License for the specific language governing permissions and
|
177
|
+
limitations under the License.
|
data/Rakefile
CHANGED
@@ -1,18 +1,38 @@
|
|
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
|
+
|
1
17
|
require 'bundler/gem_tasks'
|
2
18
|
|
3
19
|
require 'rspec/core/rake_task'
|
4
20
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
21
|
t.rspec_opts = [].tap do |a|
|
6
|
-
a
|
7
|
-
a
|
8
|
-
a
|
22
|
+
a << '--color'
|
23
|
+
a << "--format #{ENV['CI'] ? 'documentation' : 'Fuubar'}"
|
24
|
+
a << '--tag ~slow'
|
25
|
+
a << '--backtrace' if ENV['DEBUG']
|
26
|
+
a << "--seed #{ENV['SEED']}" if ENV['SEED']
|
9
27
|
end.join(' ')
|
10
28
|
end
|
11
29
|
|
12
30
|
RSpec::Core::RakeTask.new(:integration) do |t|
|
13
31
|
t.rspec_opts = [].tap do |a|
|
14
|
-
a
|
15
|
-
a
|
32
|
+
a << '--color'
|
33
|
+
a << "--format #{ENV['CI'] ? 'documentation' : 'Fuubar'}"
|
34
|
+
a << '--backtrace' if ENV['DEBUG']
|
35
|
+
a << "--seed #{ENV['SEED']}" if ENV['SEED']
|
16
36
|
end.join(' ')
|
17
37
|
end
|
18
38
|
|
@@ -0,0 +1,17 @@
|
|
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__)
|
@@ -0,0 +1,21 @@
|
|
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', github: 'chef/chef'
|
20
|
+
# gem 'poise', github: 'poise/poise'
|
21
|
+
# gem 'poise-boiler', github: 'poise/poise-boiler'
|
data/halite.gemspec
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
#
|
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
|
+
|
2
17
|
lib = File.expand_path('../lib', __FILE__)
|
3
18
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
19
|
require 'halite/version'
|
@@ -18,16 +33,12 @@ Gem::Specification.new do |spec|
|
|
18
33
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
34
|
spec.require_paths = %w{lib}
|
20
35
|
|
21
|
-
spec.add_dependency '
|
36
|
+
spec.add_dependency 'chef', '~> 12.0'
|
37
|
+
spec.add_dependency 'stove', '~> 3.2', '>= 3.2.3'
|
22
38
|
spec.add_dependency 'bundler' # Used for Bundler.load_gemspec
|
23
39
|
spec.add_dependency 'thor' # Used for Thor::Shell
|
24
40
|
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency 'rspec-
|
28
|
-
spec.add_development_dependency 'fuubar', '~> 2.0.0'
|
29
|
-
spec.add_development_dependency 'pry'
|
30
|
-
spec.add_development_dependency 'simplecov', '~> 0.9.1'
|
31
|
-
spec.add_development_dependency 'mixlib-shellout', '~> 2.0.0'
|
32
|
-
spec.add_development_dependency 'chef', '~> 12.0.0'
|
41
|
+
spec.add_development_dependency 'poise', '~> 2.0'
|
42
|
+
spec.add_development_dependency 'poise-boiler', '~> 1.0'
|
43
|
+
spec.add_development_dependency 'rspec-command', '~> 1.0'
|
33
44
|
end
|
data/lib/berkshelf/halite.rb
CHANGED
@@ -1,2 +1,27 @@
|
|
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
|
+
# Install the Halite source
|
1
18
|
require 'halite/berkshelf/helper'
|
2
19
|
::Halite::Berkshelf::Helper.install
|
20
|
+
|
21
|
+
|
22
|
+
# Berkshelf plugin loading.
|
23
|
+
# @api private
|
24
|
+
module Berkshelf
|
25
|
+
# Set up the :gem location type.
|
26
|
+
autoload :GemLocation, 'berkshelf/locations/gem'
|
27
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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
|
+
require 'halite'
|
18
|
+
|
19
|
+
|
20
|
+
module Berkshelf
|
21
|
+
# Berkshelf location plugin to install via Halite gems.
|
22
|
+
#
|
23
|
+
# @since 1.0.0
|
24
|
+
# @api private
|
25
|
+
class GemLocation < BaseLocation
|
26
|
+
attr_reader :gem_name
|
27
|
+
|
28
|
+
def initialize(*args)
|
29
|
+
super
|
30
|
+
@gem_name = options[:gem]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Always force the re-install.
|
35
|
+
#
|
36
|
+
# @see BaseLocation#installed?
|
37
|
+
def installed?
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
# Convert the gem.
|
42
|
+
#
|
43
|
+
# @see BaseLocation#install
|
44
|
+
def install
|
45
|
+
cache_path.rmtree if cache_path.exist?
|
46
|
+
cache_path.mkpath
|
47
|
+
Halite.convert(gem_name, cache_path)
|
48
|
+
validate_cached!(cache_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
# @see BaseLocation#cached_cookbook
|
52
|
+
def cached_cookbook
|
53
|
+
if cache_path.join('metadata.rb').exist?
|
54
|
+
@cached_cookbook ||= CachedCookbook.from_path(cache_path)
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Lockfile rendering for Halite gem cookbooks.
|
61
|
+
def to_lock
|
62
|
+
" gem: #{gem_name}\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
def ==(other)
|
66
|
+
other.is_a?(GemLocation) && other.gem_name == gem_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s
|
70
|
+
"gem from #{gem_name}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def inspect
|
74
|
+
"#<Berkshelf::GemLocation gem: #{gem_name}>"
|
75
|
+
end
|
76
|
+
|
77
|
+
# The path to the converted gem.
|
78
|
+
#
|
79
|
+
# @return [Pathname]
|
80
|
+
def cache_path
|
81
|
+
@cache_path ||= Pathname.new(Berkshelf.berkshelf_path).join('.cache', 'halite', dependency.name)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/halite.rb
CHANGED
@@ -1,11 +1,41 @@
|
|
1
|
-
|
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
|
+
#
|
2
16
|
|
3
|
-
require 'halite/converter'
|
4
|
-
require 'halite/gem'
|
5
17
|
|
18
|
+
# Library to convert a Ruby gem to a Chef cookbook.
|
19
|
+
#
|
20
|
+
# @since 1.0.0
|
21
|
+
# @see convert
|
6
22
|
module Halite
|
7
|
-
|
23
|
+
autoload :Converter, 'halite/converter'
|
24
|
+
autoload :Dependencies, 'halite/dependencies'
|
25
|
+
autoload :Error, 'halite/error'
|
26
|
+
autoload :Gem, 'halite/gem'
|
27
|
+
autoload :SpecHelper, 'halite/spec_helper'
|
28
|
+
autoload :VERSION, 'halite/version'
|
8
29
|
|
30
|
+
# Convert a Ruby gem to a Chef cookbook.
|
31
|
+
#
|
32
|
+
# @param gem_name [String, Gem::Specification] Gem to convert.
|
33
|
+
# @param base_path [String] Output path.
|
34
|
+
# @return [void]
|
35
|
+
# @example Converting a gem by name
|
36
|
+
# Halite.convert('mygem', 'dest')
|
37
|
+
# @example Converting a gem from a loaded gemspec
|
38
|
+
# Halite.convert(Bundler.load_gemspec('mygem.gemspec'), 'dest')
|
9
39
|
def self.convert(gem_name, base_path)
|
10
40
|
Converter.write(Gem.new(gem_name), base_path)
|
11
41
|
end
|
@@ -19,9 +19,13 @@ require 'halite/berkshelf/source'
|
|
19
19
|
require 'berkshelf/berksfile'
|
20
20
|
require 'berkshelf/downloader'
|
21
21
|
|
22
|
+
|
22
23
|
module Halite
|
23
24
|
module Berkshelf
|
24
|
-
|
25
|
+
# Helper class to monkeypatch global gem support in to Berkshelf.
|
26
|
+
#
|
27
|
+
# @since 1.0.0
|
28
|
+
# @api private
|
25
29
|
class Helper
|
26
30
|
def self.install(*args)
|
27
31
|
new(*args).install
|
@@ -30,8 +34,10 @@ module Halite
|
|
30
34
|
def initialize
|
31
35
|
end
|
32
36
|
|
37
|
+
# Install the two patches.
|
38
|
+
#
|
39
|
+
# @return [void]
|
33
40
|
def install
|
34
|
-
|
35
41
|
# Switch this to use Module#prepend at some point when I stop caring about Ruby 1.9.
|
36
42
|
::Berkshelf::Berksfile.class_exec do
|
37
43
|
old_sources = instance_method(:sources)
|
@@ -18,11 +18,18 @@ require 'halite/gem'
|
|
18
18
|
require 'berkshelf/source'
|
19
19
|
require 'berkshelf/api_client/remote_cookbook'
|
20
20
|
|
21
|
+
|
21
22
|
module Halite
|
22
23
|
module Berkshelf
|
23
|
-
|
24
|
+
# Berkshelf global source to find all Halite cookbooks in the current
|
25
|
+
# gems environment.
|
26
|
+
#
|
27
|
+
# @since 1.0.0
|
28
|
+
# @api private
|
24
29
|
class Source < ::Berkshelf::Source
|
25
30
|
def initialize
|
31
|
+
# Pretend our URL is set even though it isn't used. Otherwise berks
|
32
|
+
# complains.
|
26
33
|
super 'https://supermarket.chef.io'
|
27
34
|
end
|
28
35
|
|
@@ -46,6 +53,7 @@ module Halite
|
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
56
|
+
# Show "... from Halite gems" when installing.
|
49
57
|
def to_s
|
50
58
|
"Halite gems"
|
51
59
|
end
|