ridley 2.1.0 → 2.2.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/.ruby-version +1 -1
- data/lib/ridley/chef/cookbook.rb +30 -5
- data/lib/ridley/chef/cookbook/metadata.rb +25 -17
- data/lib/ridley/version.rb +1 -1
- data/spec/unit/ridley/chef/cookbook_spec.rb +85 -4
- 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: 0abbe5b80f97f621001f5010befbac00b1c33b97
|
4
|
+
data.tar.gz: e4a7eac60ebd38aa964556f1c55ce925d6ea906c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab776183b19fe43d27364ea31a9fa76db3b1d48a9226c8c648c0e5150ef7b34211521d3cf54f53ec1a10445f176c8ce0d07cda25e611d382f9e3a19bbc7a0ec
|
7
|
+
data.tar.gz: 2e832f64e3babcba93153e3325b620a37c64ff8972c4084a2d7dd81dd65a514242472f1f9a0649934e92ec09b3a3b9df21ad9a8044c5d1a2dfe021d6d14fe42d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0-
|
1
|
+
2.0.0-p353
|
data/lib/ridley/chef/cookbook.rb
CHANGED
@@ -33,12 +33,12 @@ module Ridley::Chef
|
|
33
33
|
# @return [Ridley::Chef::Cookbook]
|
34
34
|
def from_path(path, options = {})
|
35
35
|
path = Pathname.new(path)
|
36
|
-
metadata = if path.join(
|
37
|
-
Cookbook::Metadata.
|
38
|
-
elsif path.join(
|
39
|
-
Cookbook::Metadata.
|
36
|
+
metadata = if (metadata_file = path.join(Metadata::COMPILED_FILE_NAME)).exist?
|
37
|
+
Cookbook::Metadata.from_json(File.read(metadata_file))
|
38
|
+
elsif (metadata_file = path.join(Metadata::RAW_FILE_NAME)).exist?
|
39
|
+
Cookbook::Metadata.from_file(metadata_file)
|
40
40
|
else
|
41
|
-
raise IOError, "no
|
41
|
+
raise IOError, "no #{Metadata::COMPILED_FILE_NAME} or #{Metadata::RAW_FILE_NAME} found at #{path}"
|
42
42
|
end
|
43
43
|
|
44
44
|
metadata.name(options[:name].presence || metadata.name.presence || File.basename(path))
|
@@ -54,6 +54,7 @@ module Ridley::Chef
|
|
54
54
|
attr_reader :cookbook_name
|
55
55
|
attr_reader :path
|
56
56
|
attr_reader :metadata
|
57
|
+
|
57
58
|
# @return [Hashie::Mash]
|
58
59
|
# a Hashie::Mash containing Cookbook file category names as keys and an Array of Hashes
|
59
60
|
# containing metadata about the files belonging to that category. This is used
|
@@ -117,6 +118,25 @@ module Ridley::Chef
|
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
121
|
+
# Compiles the raw metadata of the cookbook and writes it to a metadata.json file at the given
|
122
|
+
# out path. The default out path is the directory containing the cookbook itself.
|
123
|
+
#
|
124
|
+
# @param [String] out
|
125
|
+
# directory to output compiled metadata to
|
126
|
+
def compile_metadata(out = self.path)
|
127
|
+
File.open(File.join(out, Metadata::COMPILED_FILE_NAME), "w+") do |f|
|
128
|
+
f.write(metadata.to_json)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns true if the cookbook instance has a compiled metadata file and false if it
|
133
|
+
# does not.
|
134
|
+
#
|
135
|
+
# @return [Boolean]
|
136
|
+
def compiled_metadata?
|
137
|
+
manifest[:root_files].any? { |file| file[:name].downcase == Metadata::COMPILED_FILE_NAME }
|
138
|
+
end
|
139
|
+
|
120
140
|
# @param [Symbol] category
|
121
141
|
# the category of file to generate metadata about
|
122
142
|
# @param [String] target
|
@@ -168,6 +188,11 @@ module Ridley::Chef
|
|
168
188
|
"#{cookbook_name}-#{version}"
|
169
189
|
end
|
170
190
|
|
191
|
+
# Reload the cookbook from the files located on disk at `#path`.
|
192
|
+
def reload
|
193
|
+
load_files
|
194
|
+
end
|
195
|
+
|
171
196
|
def validate
|
172
197
|
raise IOError, "No Cookbook found at: #{path}" unless path.exist?
|
173
198
|
|
@@ -30,23 +30,26 @@ module Ridley::Chef
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
NAME
|
34
|
-
DESCRIPTION
|
35
|
-
LONG_DESCRIPTION
|
36
|
-
MAINTAINER
|
37
|
-
MAINTAINER_EMAIL
|
38
|
-
LICENSE
|
39
|
-
PLATFORMS
|
40
|
-
DEPENDENCIES
|
41
|
-
RECOMMENDATIONS
|
42
|
-
SUGGESTIONS
|
43
|
-
CONFLICTING
|
44
|
-
PROVIDING
|
45
|
-
REPLACING
|
46
|
-
ATTRIBUTES
|
47
|
-
GROUPINGS
|
48
|
-
RECIPES
|
49
|
-
VERSION
|
33
|
+
NAME = 'name'.freeze
|
34
|
+
DESCRIPTION = 'description'.freeze
|
35
|
+
LONG_DESCRIPTION = 'long_description'.freeze
|
36
|
+
MAINTAINER = 'maintainer'.freeze
|
37
|
+
MAINTAINER_EMAIL = 'maintainer_email'.freeze
|
38
|
+
LICENSE = 'license'.freeze
|
39
|
+
PLATFORMS = 'platforms'.freeze
|
40
|
+
DEPENDENCIES = 'dependencies'.freeze
|
41
|
+
RECOMMENDATIONS = 'recommendations'.freeze
|
42
|
+
SUGGESTIONS = 'suggestions'.freeze
|
43
|
+
CONFLICTING = 'conflicting'.freeze
|
44
|
+
PROVIDING = 'providing'.freeze
|
45
|
+
REPLACING = 'replacing'.freeze
|
46
|
+
ATTRIBUTES = 'attributes'.freeze
|
47
|
+
GROUPINGS = 'groupings'.freeze
|
48
|
+
RECIPES = 'recipes'.freeze
|
49
|
+
VERSION = 'version'.freeze
|
50
|
+
|
51
|
+
COMPILED_FILE_NAME = "metadata.json".freeze
|
52
|
+
RAW_FILE_NAME = "metadata.rb".freeze
|
50
53
|
|
51
54
|
COMPARISON_FIELDS = [
|
52
55
|
:name, :description, :long_description, :maintainer,
|
@@ -439,6 +442,11 @@ module Ridley::Chef
|
|
439
442
|
}
|
440
443
|
end
|
441
444
|
|
445
|
+
# @return [String]
|
446
|
+
def to_json
|
447
|
+
JSON.fast_generate(to_hash)
|
448
|
+
end
|
449
|
+
|
442
450
|
def from_hash(o)
|
443
451
|
@name = o[NAME] if o.has_key?(NAME)
|
444
452
|
@description = o[DESCRIPTION] if o.has_key?(DESCRIPTION)
|
data/lib/ridley/version.rb
CHANGED
@@ -40,20 +40,44 @@ describe Ridley::Chef::Cookbook do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context "when a metadata.
|
43
|
+
context "when a metadata.json is missing but metadata.rb is present" do
|
44
44
|
let(:cookbook_path) { tmp_path.join("temp_cookbook").to_s }
|
45
45
|
|
46
46
|
before do
|
47
47
|
FileUtils.mkdir_p(cookbook_path)
|
48
|
-
File.open(File.join(cookbook_path, 'metadata.
|
49
|
-
f.write
|
48
|
+
File.open(File.join(cookbook_path, 'metadata.rb'), 'w+') do |f|
|
49
|
+
f.write <<-EOH
|
50
|
+
name 'rspec_test'
|
51
|
+
EOH
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
it "sets the name of the cookbook from the metadata.
|
55
|
+
it "sets the name of the cookbook from the metadata.rb" do
|
54
56
|
subject.from_path(cookbook_path).cookbook_name.should eql("rspec_test")
|
55
57
|
end
|
56
58
|
end
|
59
|
+
|
60
|
+
context "when a metadata.json and metadata.rb are both present" do
|
61
|
+
let(:cookbook_path) { tmp_path.join("temp_cookbook").to_s }
|
62
|
+
|
63
|
+
before do
|
64
|
+
FileUtils.mkdir_p(cookbook_path)
|
65
|
+
|
66
|
+
File.open(File.join(cookbook_path, 'metadata.json'), 'w+') do |f|
|
67
|
+
f.write JSON.fast_generate(name: "json_metadata")
|
68
|
+
end
|
69
|
+
|
70
|
+
File.open(File.join(cookbook_path, 'metadata.rb'), 'w+') do |f|
|
71
|
+
f.write <<-EOH
|
72
|
+
name 'ruby_metadata'
|
73
|
+
EOH
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "prefers the metadata.json" do
|
78
|
+
subject.from_path(cookbook_path).cookbook_name.should eql("json_metadata")
|
79
|
+
end
|
80
|
+
end
|
57
81
|
end
|
58
82
|
|
59
83
|
describe "::checksum" do
|
@@ -82,6 +106,63 @@ describe Ridley::Chef::Cookbook do
|
|
82
106
|
end
|
83
107
|
end
|
84
108
|
|
109
|
+
describe "#compile_metadata" do
|
110
|
+
let(:cookbook_path) { tmp_path.join("temp_cookbook").to_s }
|
111
|
+
subject { described_class.from_path(cookbook_path) }
|
112
|
+
before do
|
113
|
+
FileUtils.mkdir_p(cookbook_path)
|
114
|
+
File.open(File.join(cookbook_path, "metadata.rb"), "w+") do |f|
|
115
|
+
f.write <<-EOH
|
116
|
+
name "rspec_test"
|
117
|
+
version "1.2.3"
|
118
|
+
EOH
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "compiles the raw metadata.rb into a metadata.json file in the path of the cookbook" do
|
123
|
+
expect(subject.compiled_metadata?).to be_false
|
124
|
+
subject.compile_metadata
|
125
|
+
subject.reload
|
126
|
+
expect(subject.compiled_metadata?).to be_true
|
127
|
+
expect(subject.cookbook_name).to eql("rspec_test")
|
128
|
+
expect(subject.version).to eql("1.2.3")
|
129
|
+
end
|
130
|
+
|
131
|
+
context "when given an output path to write the metadata to" do
|
132
|
+
let(:out_path) { tmp_path.join("outpath") }
|
133
|
+
before { FileUtils.mkdir_p(out_path) }
|
134
|
+
|
135
|
+
it "writes the compiled metadata to a metadata.json file at the given out path" do
|
136
|
+
subject.compile_metadata(out_path)
|
137
|
+
expect(File.exist?(File.join(out_path, "metadata.json"))).to be_true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#compiled_metadata?" do
|
143
|
+
let(:cookbook_path) { tmp_path.join("temp_cookbook").to_s }
|
144
|
+
subject { described_class.from_path(cookbook_path) }
|
145
|
+
before do
|
146
|
+
FileUtils.mkdir_p(cookbook_path)
|
147
|
+
FileUtils.touch(File.join(cookbook_path, "metadata.rb"))
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when a metadata.json file is present" do
|
151
|
+
before do
|
152
|
+
File.open(File.join(cookbook_path, 'metadata.json'), 'w+') do |f|
|
153
|
+
f.write JSON.fast_generate(name: "json_metadata")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
its(:compiled_metadata?) { should be_true }
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when a metadata.json file is not present" do
|
161
|
+
before { FileUtils.rm_f(File.join(cookbook_path, "metadata.json")) }
|
162
|
+
its(:compiled_metadata?) { should be_false }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
85
166
|
describe "#manifest" do
|
86
167
|
it "returns a Mash with a key for each cookbook file category" do
|
87
168
|
[
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -416,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
416
416
|
version: '0'
|
417
417
|
requirements: []
|
418
418
|
rubyforge_project:
|
419
|
-
rubygems_version: 2.0.
|
419
|
+
rubygems_version: 2.0.14
|
420
420
|
signing_key:
|
421
421
|
specification_version: 4
|
422
422
|
summary: A reliable Chef API client with a clean syntax
|