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

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.expand_path(path)
end

Instance Attribute Details

#pathString (readonly)


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

def path
  @path
end

Instance Method Details

#contentString

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

#md5String

The MD5 checksum for this file.


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.

Raises:


102
103
104
# File 'lib/omnibus/package.rb', line 102

def 
   ||= .for_package(self)
end

#nameString

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

#sha1String

The SHA1 checksum for this file.


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

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

#sha256String

The SHA256 checksum for this file.


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

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

#sha512String

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.

Raises:


114
115
116
117
118
119
120
121
122
123
124
# File 'lib/omnibus/package.rb', line 114

def validate!
  unless File.exist?(path)
    raise NoPackageFile.new(path)
  end

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

  true
end