Module: Pray::ManifestMethods
- Included in:
- Pray
- Defined in:
- lib/pray/manifest.rb,
lib/pray/manifest_parser.rb,
lib/pray/manifest_formatter.rb,
lib/pray/manifest_parser_blocks.rb,
lib/pray/manifest_parser_helpers.rb
Defined Under Namespace
Modules: ParserBlocks, ParserHelpers
Classes: BlockParser
Class Method Summary
collapse
Class Method Details
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/pray/manifest_formatter.rb', line 7
def format_package_declaration(package)
parts = ["pray \"#{package.name}\""]
parts << "\"#{package.constraint}\"" unless package.constraint == "*"
parts << "path: \"#{package.path}\"" if package.path
parts << "source: \"#{package.source}\"" if package.source
parts << "git: \"#{package.git}\"" if package.git
parts << "tag: \"#{package.tag}\"" if package.tag
parts << "rev: \"#{package.rev}\"" if package.rev
parts << "tarball: \"#{package.tarball}\"" if package.tarball
parts << "oci: \"#{package.oci}\"" if package.oci
parts << "file: \"#{package.file}\"" if package.file
unless package.exports.empty?
parts << if package.exports.length == 1
"export: \"#{package.exports.first}\""
else
"exports: [#{format_string_keyword_list(package.exports)}]"
end
end
parts << "targets: [#{format_string_keyword_list(package.targets)}]" unless package.targets.empty?
parts << "features: [#{format_string_keyword_list(package.features)}]" unless package.features.empty?
parts << "optional: true" if package.optional
parts.join(", ")
end
|
52
53
54
|
# File 'lib/pray/manifest_formatter.rb', line 52
def format_string_keyword_list(values)
values.map { |value| "\"#{value}\"" }.join(", ")
end
|
.parse_manifest(text) ⇒ Object
.read_manifest_text(manifest_path) ⇒ Object
113
114
115
116
117
|
# File 'lib/pray/manifest.rb', line 113
def read_manifest_text(manifest_path)
File.read(manifest_path)
rescue Errno::ENOENT
raise Error.manifest("missing #{manifest_path}; run pray init to create one")
end
|
.replace_package_declaration(text, package) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/pray/manifest_formatter.rb', line 31
def replace_package_declaration(text, package)
name = package.name
prefixes = [
"pray \"#{name}\"", "pray '#{name}'",
"use \"#{name}\"", "include \"#{name}\"",
"agent \"#{name}\"", "agent '#{name}'",
"package \"#{name}\"", "package '#{name}'"
]
lines = text.lines.map(&:chomp)
index = lines.index { |line|
trimmed = line.lstrip
prefixes.any? { |prefix| trimmed.start_with?(prefix) }
}
raise Error.manifest("package #{name} not found in manifest") unless index
lines[index] = format_package_declaration(package)
output = lines.join("\n")
output += "\n" if text.end_with?("\n") && !output.end_with?("\n")
output
end
|