Example Utility
require 'masterinstaller'
require 'fileinstaller'
require 'sqlinstaller'
m = MasterInstaller.new
m.register(FileInstaller.new("xyz.rb", "bin"))
m.register SqlInstaller.new(
"INSERT INTO a_table VALUES(1,2,3);" )
commands = ['install', 'uninstall', 'backup']
ARGV.each do |command|
puts "Command is #{command}"
m.send(command) if commands.include? command
puts
end
|
Output
Command is backup
Backing up file bin/xyz.rb
Backing up SQL
Command is install
Installing file bin/xyz.rb
Installing SQL
|
|
- require finds the file and loads it (once)
- new sent to a Class object will cause a new instance to be created. Parameters passed to new will automatically be passed to initialize.
- Parenthesis are optional if the result is not ambiguous.
- ARGV is a list of command line arguments
- ? as a method name suffix (e.g. include?) indicates that the method returns a true/false value.
- No interface declaration is needed for installers. As long as they implement the needed methods, the master installer can use them.
- if can be used as a suffix
|