class Omnibus::Package

Attributes

path[R]

@return [String]

Public Class Methods

new(path) click to toggle source

Create a new package from the given path.

@param [String] path

the path to the package on disk
# File lib/omnibus/package.rb, line 34
def initialize(path)
  @path = File.expand_path(path)
end

Public Instance Methods

content() click to toggle source

The actual contents of the package.

@return [String]

# File lib/omnibus/package.rb, line 88
def content
  @content ||= IO.read(path)
rescue Errno::ENOENT
  raise NoPackageFile.new(path)
end
md5() click to toggle source

The MD5 checksum for this file.

@return [String]

# File lib/omnibus/package.rb, line 52
def md5
  @md5 ||= digest(path, :md5)
end
metadata() click to toggle source

The parsed contents of the metadata.

@raise [NoPackageMetadataFile] if the {#metadata} does not exist @raise [FFI_Yajl::ParseError] if the JSON is not valid

@return [Hash<Symbol, String>]

# File lib/omnibus/package.rb, line 102
def metadata
  @metadata ||= Metadata.for_package(self)
end
metadata=(metadata) click to toggle source

Set the metadata for this package

@param [Metadata] metadata

# File lib/omnibus/package.rb, line 111
def metadata=(metadata)
  @metadata = metadata
end
name() click to toggle source

The shortname of this package (the basename of the file).

@return [String]

# File lib/omnibus/package.rb, line 43
def name
  @name ||= File.basename(path)
end
sha1() click to toggle source

The SHA1 checksum for this file.

@return [String]

# File lib/omnibus/package.rb, line 61
def sha1
  @sha1 ||= digest(path, :sha1)
end
sha256() click to toggle source

The SHA256 checksum for this file.

@return [String]

# File lib/omnibus/package.rb, line 70
def sha256
  @sha256 ||= digest(path, :sha256)
end
sha512() click to toggle source

The SHA512 checksum for this file.

@return [String]

# File lib/omnibus/package.rb, line 79
def sha512
  @sha512 ||= digest(path, :sha512)
end
validate!() click to toggle source

Validate the presence of the required components for the package.

@raise [NoPackageFile] if the package is not present @raise [NoPackageMetadataFile] if the metadata file is not present

@return [true]

# File lib/omnibus/package.rb, line 123
def validate!
  unless File.exist?(path)
    raise NoPackageFile.new(path)
  end

  unless File.exist?(metadata.path)
    raise NoPackageMetadataFile.new(metadata.path)
  end

  true
end