Class: Omnibus::Package

Inherits:
Object
  • Object
show all
Includes:
Digestable
Defined in:
lib/omnibus/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

#initialize(path) ⇒ Package

Create a new package from the given path.

Parameters:

  • path (String)

    the path to the package on disk



34
35
36
# File 'lib/omnibus/package.rb', line 34

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathString (readonly)

Returns:

  • (String)


26
27
28
# File 'lib/omnibus/package.rb', line 26

def path
  @path
end

Instance Method Details

#contentString

The actual contents of the package.

Returns:

  • (String)


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

#md5String

The MD5 checksum for this file.

Returns:

  • (String)


52
53
54
# File 'lib/omnibus/package.rb', line 52

def md5
  @md5 ||= digest(path, :md5)
end

#metadataHash<Symbol, String>

The parsed contents of the metadata.

Returns:

  • (Hash<Symbol, String>)

Raises:



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

Parameters:



111
112
113
# File 'lib/omnibus/package.rb', line 111

def metadata=()
  @metadata = 
end

#nameString

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

Returns:

  • (String)


43
44
45
# File 'lib/omnibus/package.rb', line 43

def name
  @name ||= File.basename(path)
end

#sha1String

The SHA1 checksum for this file.

Returns:

  • (String)


61
62
63
# File 'lib/omnibus/package.rb', line 61

def sha1
  @sha1 ||= digest(path, :sha1)
end

#sha256String

The SHA256 checksum for this file.

Returns:

  • (String)


70
71
72
# File 'lib/omnibus/package.rb', line 70

def sha256
  @sha256 ||= digest(path, :sha256)
end

#sha512String

The SHA512 checksum for this file.

Returns:

  • (String)


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.

Returns:

  • (true)

Raises:



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