Class: PackageManager::Base
- Inherits:
-
Object
- Object
- PackageManager::Base
- Defined in:
- lib/package_manager/base.rb,
lib/package_manager/base.rb
Constant Summary collapse
- KNOWN_PACKAGE_MANAGERS =
{ 'apt' => Apt, 'dpkg' => Dpkg, 'fink' => Fink, 'port' => Port, 'rpm' => Rpm, 'yum' => Yum }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_available(package_match) ⇒ Object
Returns an array of matches.
-
#find_installed(package_match) ⇒ Object
Returns an array of matches.
-
#install(package) ⇒ Object
Returns true if the package installed successfully.
-
#install_file(file) ⇒ Object
Returns true if the package installed successfully.
-
#list_contents(package) ⇒ Object
Returns an array of file names.
-
#provides(file) ⇒ Object
Returns the package name if found, or an empty string.
-
#uninstall(package) ⇒ Object
Returns true if the package uninstalled successfully.
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/package_manager/base.rb', line 19 def name @name end |
Class Method Details
.load(package_manager = guess_package_manager) ⇒ Object
28 29 30 31 |
# File 'lib/package_manager/base.rb', line 28 def self.load( package_manager = guess_package_manager ) raise 'Unknown package manager' if KNOWN_PACKAGE_MANAGERS[ package_manager ].nil? KNOWN_PACKAGE_MANAGERS[ package_manager ].new end |
Instance Method Details
#find_available(package_match) ⇒ Object
Returns an array of matches
34 35 36 |
# File 'lib/package_manager/base.rb', line 34 def find_available( package_match ) run_command( find_available_command, [ package_match ] ).split( "\n" ) end |
#find_installed(package_match) ⇒ Object
Returns an array of matches
39 40 41 |
# File 'lib/package_manager/base.rb', line 39 def find_installed( package_match ) run_command( find_installed_command, [ package_match ] ).split( "\n" ).uniq end |
#install(package) ⇒ Object
Returns true if the package installed successfully
49 50 51 |
# File 'lib/package_manager/base.rb', line 49 def install( package ) exec_command( 'sudo ' + install_command, [ package ], { :echo_output => true } ) end |
#install_file(file) ⇒ Object
Returns true if the package installed successfully
54 55 56 57 |
# File 'lib/package_manager/base.rb', line 54 def install_file( file ) raise "The file '#{ file }' does not exist" if ! File.exist?( file ) exec_command( 'sudo ' + install_file_command, [ file ], { :echo_output => true } ) end |
#list_contents(package) ⇒ Object
Returns an array of file names
44 45 46 |
# File 'lib/package_manager/base.rb', line 44 def list_contents( package ) run_command( list_contents_command, [ package ] ).split( "\n" ) end |
#provides(file) ⇒ Object
Returns the package name if found, or an empty string
65 66 67 68 |
# File 'lib/package_manager/base.rb', line 65 def provides( file ) raise "The file '#{ file }' does not exist" if ! File.exist?( file ) run_command( provides_command, [ file ] ) end |
#uninstall(package) ⇒ Object
Returns true if the package uninstalled successfully
60 61 62 |
# File 'lib/package_manager/base.rb', line 60 def uninstall( package ) exec_command( 'sudo ' + uninstall_command, [ package ], { :echo_output => true } ) end |