Class: Debeasy::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/debeasy/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Package

Create a new Debeasy::Package object.

Arguments:

path: (String)

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/debeasy/package.rb', line 21

def initialize(path)
  @path = path
  raise NotAPackageError, "#{path} is not a Debian package" unless is_package_file?
  @package_file = Archive.read_open_filename(path)
  @fields = {}
  @filelist = []
  extract_files
  parse_control_file
  generate_checksums
  get_size
  get_filename
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



46
47
48
# File 'lib/debeasy/package.rb', line 46

def method_missing(m, *args, &block)
  @fields.has_key?(m.to_s) ? @fields[m.to_s] : nil
end

Instance Attribute Details

#control_file_contentsObject (readonly)

Returns the value of attribute control_file_contents.



12
13
14
# File 'lib/debeasy/package.rb', line 12

def control_file_contents
  @control_file_contents
end

#filelistObject (readonly)

Returns the value of attribute filelist.



12
13
14
# File 'lib/debeasy/package.rb', line 12

def filelist
  @filelist
end

#package_fileObject (readonly)

Returns the value of attribute package_file.



11
12
13
# File 'lib/debeasy/package.rb', line 11

def package_file
  @package_file
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/debeasy/package.rb', line 11

def path
  @path
end

#postinst_contentsObject (readonly)

Returns the value of attribute postinst_contents.



14
15
16
# File 'lib/debeasy/package.rb', line 14

def postinst_contents
  @postinst_contents
end

#postrm_contentsObject (readonly)

Returns the value of attribute postrm_contents.



14
15
16
# File 'lib/debeasy/package.rb', line 14

def postrm_contents
  @postrm_contents
end

#preinst_contentsObject (readonly)

Returns the value of attribute preinst_contents.



13
14
15
# File 'lib/debeasy/package.rb', line 13

def preinst_contents
  @preinst_contents
end

#prerm_contentsObject (readonly)

Returns the value of attribute prerm_contents.



13
14
15
# File 'lib/debeasy/package.rb', line 13

def prerm_contents
  @prerm_contents
end

Instance Method Details

#[](field) ⇒ Object

Utility method to get the field in a hash-like way.



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

def [](field)
  @fields.has_key?(field.to_s) ? @fields[field.to_s] : nil
end

#fieldsObject

Lists all the available fields on the package.



36
37
38
# File 'lib/debeasy/package.rb', line 36

def fields
  @fields.keys
end

#to_hashObject

Get package metadata as a hash.



42
43
44
# File 'lib/debeasy/package.rb', line 42

def to_hash
  @fields
end