Class: Uberinstaller::PackageManager::Base
- Inherits:
-
Object
- Object
- Uberinstaller::PackageManager::Base
- Includes:
- Loggable
- Defined in:
- lib/uberinstaller/package_managers/base.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#debug(action, args = []) ⇒ Object
Print to log for debug purposes.
-
#initialize ⇒ Base
constructor
Create the package manager.
-
#make_command(action, args = []) ⇒ Object
Creates a command putting together action and arguments.
-
#method_missing(m, *args, &block) ⇒ Object
All execution is handled dinamically via this function.
-
#set_commands ⇒ Object
This method is a stub, here only for reference.
Methods included from Loggable
configure_logger_for, #logger, logger_for
Constructor Details
#initialize ⇒ Base
Create the package manager
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/uberinstaller/package_managers/base.rb', line 16 def initialize @commands = Hash.new @commands = { :add_repository => nil, :info => nil, :install => nil, :search => nil, :update => nil, :upgrade => nil } set_commands end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
All execution is handled dinamically via this function
If the method called is in the @commands Hash, the specified action is performed, otherwise a NoMethodError exception
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/uberinstaller/package_managers/base.rb', line 64 def method_missing(m, *args, &block) if @commands.has_key? m debug m, args unless Config.dry_run Open3.popen3(make_command(m, args)) { |stdin, stdout, stderr, wait_thr| pid = wait_thr.pid # pid of the started process. logger.debug "Running pid: #{pid}" logger.debug stdout.readlines exit_status = wait_thr.value.to_i # Process::Status object returned. logger.debug "Exit status: #{exit_status}" logger.error 'Some error happended during execution:' unless exit_status == 0 logger.error stderr.readlines unless exit_status == 0 } end else raise NoMethodError end end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
13 14 15 |
# File 'lib/uberinstaller/package_managers/base.rb', line 13 def commands @commands end |
Instance Method Details
#debug(action, args = []) ⇒ Object
Print to log for debug purposes
41 42 43 44 45 |
# File 'lib/uberinstaller/package_managers/base.rb', line 41 def debug(action, args = []) logger.debug "action : #{action}" logger.debug "args : #{args.join(', ')}" unless args.empty? logger.debug "command: #{make_command(action, args)}" end |
#make_command(action, args = []) ⇒ Object
Creates a command putting together action and arguments
51 52 53 54 55 56 |
# File 'lib/uberinstaller/package_managers/base.rb', line 51 def make_command(action, args = []) command = @commands[action.to_sym] command += " '" + args.join(' ') + "'" unless args.empty? command end |
#set_commands ⇒ Object
This method is a stub, here only for reference
In every subclass of PackageManager::Base this method must be redefined specifying the package manager specific command ( see Apt and Dpkg for example )
35 |
# File 'lib/uberinstaller/package_managers/base.rb', line 35 def set_commands; end |