Class: Bosh::Cli::Resources::Package
- Defined in:
- lib/cli/resources/package.rb
Constant Summary collapse
- BUILD_HOOK_FILES =
['packaging', 'pre_packaging']
Instance Attribute Summary collapse
-
#package_base ⇒ Object
readonly
Returns the value of attribute package_base.
-
#release_base ⇒ Object
readonly
Returns the value of attribute release_base.
Class Method Summary collapse
Instance Method Summary collapse
- #additional_fingerprints ⇒ Object
- #dependencies ⇒ Object
- #files ⇒ Object
- #format_fingerprint(digest, filename, name, file_mode) ⇒ Object
-
#initialize(package_base, release_base) ⇒ Package
constructor
A new instance of Package.
- #name ⇒ Object
- #plural_type ⇒ Object
- #run_script(script_name, *args) ⇒ Object
- #singular_type ⇒ Object
- #spec ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(package_base, release_base) ⇒ Package
Returns a new instance of Package.
24 25 26 27 |
# File 'lib/cli/resources/package.rb', line 24 def initialize(package_base, release_base) @release_base = Pathname.new(release_base) @package_base = Pathname.new(package_base) end |
Instance Attribute Details
#package_base ⇒ Object (readonly)
Returns the value of attribute package_base.
22 23 24 |
# File 'lib/cli/resources/package.rb', line 22 def package_base @package_base end |
#release_base ⇒ Object (readonly)
Returns the value of attribute release_base.
22 23 24 |
# File 'lib/cli/resources/package.rb', line 22 def release_base @release_base end |
Class Method Details
.discover(release_base) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/cli/resources/package.rb', line 13 def self.discover(release_base) Dir[File.join(release_base, 'packages', '*')].inject([]) do |packages, package_base| if File.directory?(package_base) packages << new(package_base, release_base) end packages end end |
Instance Method Details
#additional_fingerprints ⇒ Object
94 95 96 |
# File 'lib/cli/resources/package.rb', line 94 def additional_fingerprints dependencies end |
#dependencies ⇒ Object
39 40 41 |
# File 'lib/cli/resources/package.rb', line 39 def dependencies @dependencies ||= Array(spec['dependencies']).sort end |
#files ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cli/resources/package.rb', line 51 def files resolve_globs known_files = {} files = [] files += resolved_globs.map do |match| known_files[match.path] = true [match.full_path, match.path] end BUILD_HOOK_FILES.each do |build_hook_file| source_file = package_base.join(build_hook_file) if source_file.exist? if known_files.has_key?(build_hook_file) raise Bosh::Cli::InvalidPackage, "Package '#{name}' has '#{build_hook_file}' file " + "which conflicts with BOSH packaging" end files << [source_file.to_s, build_hook_file] end end files end |
#format_fingerprint(digest, filename, name, file_mode) ⇒ Object
98 99 100 101 |
# File 'lib/cli/resources/package.rb', line 98 def format_fingerprint(digest, filename, name, file_mode) is_hook = BUILD_HOOK_FILES.include?(name) "%s%s%s" % [name, digest, is_hook ? '' : file_mode] end |
#name ⇒ Object
35 36 37 |
# File 'lib/cli/resources/package.rb', line 35 def name spec['name'] end |
#plural_type ⇒ Object
47 48 49 |
# File 'lib/cli/resources/package.rb', line 47 def plural_type 'packages' end |
#run_script(script_name, *args) ⇒ Object
103 104 105 106 107 |
# File 'lib/cli/resources/package.rb', line 103 def run_script(script_name, *args) if BUILD_HOOK_FILES.include?(script_name.to_s) send(:"run_script_#{script_name}", *args) end end |
#singular_type ⇒ Object
43 44 45 |
# File 'lib/cli/resources/package.rb', line 43 def singular_type 'package' end |
#spec ⇒ Object
29 30 31 32 33 |
# File 'lib/cli/resources/package.rb', line 29 def spec @spec ||= load_yaml_file(package_base.join('spec')) rescue raise Bosh::Cli::InvalidPackage, 'Package spec is missing' end |
#validate! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cli/resources/package.rb', line 76 def validate! basename = File.basename(package_base.to_s) unless name == basename raise Bosh::Cli::InvalidPackage, "Found '#{name}' package in '#{basename}' directory, please fix it" end unless name.bosh_valid_id? raise Bosh::Cli::InvalidPackage, "Package name, '#{name}', should be a valid BOSH identifier" end unless spec['files'].is_a?(Array) && spec['files'].size > 0 raise Bosh::Cli::InvalidPackage, "Package '#{name}' doesn't include any files" end resolve_globs end |