Class: Disloku::Config::Options
- Inherits:
-
Object
- Object
- Disloku::Config::Options
- Defined in:
- lib/disloku/config/Options.rb
Instance Method Summary collapse
- #getCommand(cmdKey, *args) ⇒ Object
-
#initialize(config, cliOptions) ⇒ Options
constructor
A new instance of Options.
- #method_missing(name, *args, &block) ⇒ Object
- #processInputDefaults ⇒ Object
- #processPackageDir ⇒ Object
Constructor Details
#initialize(config, cliOptions) ⇒ Options
Returns a new instance of Options.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/disloku/config/Options.rb', line 12 def initialize(config, cliOptions) @options = { :ignoreDeleteErrors => false, :createDeletesFile => false, :allowOverride => false, :target => "default", :packageDir => :temp, :inputDefault => :none, :assumeYes => false, :assumeVeryYes => false, :openPackageDir => true, :openDirCmd => :openDir, } @options.each_key() do |key| if (cliOptions.has_key?(key.to_s())) @options[key] = cliOptions[key.to_s()] elsif (config[key.to_s()] != nil) @options[key] = config[key.to_s()].value() end end processPackageDir() processInputDefaults() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/disloku/config/Options.rb', line 61 def method_missing(name, *args, &block) if (!@options.has_key?(name)) raise ArgumentError.new("There's no option '#{name}' here") end return @options[name] end |
Instance Method Details
#getCommand(cmdKey, *args) ⇒ Object
69 70 71 72 |
# File 'lib/disloku/config/Options.rb', line 69 def getCommand(cmdKey, *args) cmd = @options[cmdKey] return cmd.kind_of?(Symbol) ? OsCommands.get(cmd, *args) : SysCmd.new(cmd, *args) end |
#processInputDefaults ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/disloku/config/Options.rb', line 53 def processInputDefaults() if (@options[:assumeVeryYes] == true) @options[:inputDefault] = :veryYes elsif (@options[:assumeYes] == true) @options[:inputDefault] = :yes end end |
#processPackageDir ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/disloku/config/Options.rb', line 38 def processPackageDir() if (@options[:packageDir] == :temp) @options[:packageDir] = Dir.mktmpdir("disloku") Log.instance.debug("Creating tmp directory #{@options[:packageDir]}") # make sure the temp directory is deleted when the program exists at_exit { Log.instance.debug("Removing tmp directory #{@options[:packageDir]}") FileUtils.rm_r(@options[:packageDir], :force => true) } else @options[:packageDir] = File.(@options[:packageDir]) end end |