Class: Omnibus::Package
- Inherits:
-
Object
- Object
- Omnibus::Package
- Includes:
- Digestable
- Defined in:
- lib/omnibus/package.rb
Instance Attribute Summary collapse
- #path ⇒ String readonly
Instance Method Summary collapse
-
#content ⇒ String
The actual contents of the package.
-
#initialize(path) ⇒ Package
constructor
Create a new package from the given path.
-
#md5 ⇒ String
The MD5 checksum for this file.
-
#metadata ⇒ Hash<Symbol, String>
The parsed contents of the metadata.
-
#metadata=(metadata) ⇒ Object
Set the metadata for this package.
-
#name ⇒ String
The shortname of this package (the basename of the file).
-
#sha1 ⇒ String
The SHA1 checksum for this file.
-
#sha256 ⇒ String
The SHA256 checksum for this file.
-
#sha512 ⇒ String
The SHA512 checksum for this file.
-
#validate! ⇒ true
Validate the presence of the required components for the package.
Methods included from Digestable
#digest, #digest_directory, included
Constructor Details
#initialize(path) ⇒ Package
Create a new package from the given path.
34 35 36 |
# File 'lib/omnibus/package.rb', line 34 def initialize(path) @path = File.(path) end |
Instance Attribute Details
#path ⇒ String (readonly)
26 27 28 |
# File 'lib/omnibus/package.rb', line 26 def path @path end |
Instance Method Details
#content ⇒ String
The actual contents of the package.
88 89 90 91 92 |
# File 'lib/omnibus/package.rb', line 88 def content @content ||= IO.read(path) rescue Errno::ENOENT raise NoPackageFile.new(path) end |
#md5 ⇒ String
The MD5 checksum for this file.
52 53 54 |
# File 'lib/omnibus/package.rb', line 52 def md5 @md5 ||= digest(path, :md5) end |
#metadata ⇒ Hash<Symbol, String>
The parsed contents of the metadata.
102 103 104 |
# File 'lib/omnibus/package.rb', line 102 def @metadata ||= Metadata.for_package(self) end |
#metadata=(metadata) ⇒ Object
Set the metadata for this package
111 112 113 |
# File 'lib/omnibus/package.rb', line 111 def () @metadata = end |
#name ⇒ String
The shortname of this package (the basename of the file).
43 44 45 |
# File 'lib/omnibus/package.rb', line 43 def name @name ||= File.basename(path) end |
#sha1 ⇒ String
The SHA1 checksum for this file.
61 62 63 |
# File 'lib/omnibus/package.rb', line 61 def sha1 @sha1 ||= digest(path, :sha1) end |
#sha256 ⇒ String
The SHA256 checksum for this file.
70 71 72 |
# File 'lib/omnibus/package.rb', line 70 def sha256 @sha256 ||= digest(path, :sha256) end |
#sha512 ⇒ String
The SHA512 checksum for this file.
79 80 81 |
# File 'lib/omnibus/package.rb', line 79 def sha512 @sha512 ||= digest(path, :sha512) end |
#validate! ⇒ true
Validate the presence of the required components for the package.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/omnibus/package.rb', line 123 def validate! unless File.exist?(path) raise NoPackageFile.new(path) end unless File.exist?(.path) raise NoPackageMetadataFile.new(.path) end true end |