lib/rconf/configurator.rb in rconf-0.7.10 vs lib/rconf/configurator.rb in rconf-0.7.11
- old
+ new
@@ -63,11 +63,12 @@
# settings(Hash):: Settings descriptions indexed by names
#
# === Return
# true:: Always return true
def settings(settings)
- @all_settings = settings
+ default_settings = { :only_if => 'Ruby code that should return true for configurator to proceed' }
+ @all_settings = settings.merge(default_settings)
true
end
# Store required settings for validation
#
@@ -95,11 +96,10 @@
#
# === Return
# nil:: If settings are valid for this configurator
# error(String):: Error message otherwise
def validate
- init
required = self.class.required_settings
return nil unless required
missing = required.flatten.select { |s| !@settings_values.include?(s) }
error = case missing.size
when 0 then nil
@@ -117,16 +117,18 @@
# args:: Pass-through arguments, given to platform specific implementation
#
# === Return
# true:: Always return true
def run(*args)
- init
- sha = Profile.configurator_signature(self.class.key)
+ key = "#{self.class.key}-#{@index}"
+ sha = Profile.configurator_signature(key)
sig = signature
if sha != sig
- Platform.dispatch(*args) { :run }
- Profile.set_configurator_signature(self.class.key, sig)
+ if only_if.nil? || instance_eval(only_if)
+ Platform.dispatch(*args) { :run }
+ Profile.set_configurator_signature(key, sig)
+ end
end
true
end
# Called even if configuration is already done for steps that must
@@ -155,11 +157,10 @@
#
# === Returns
# value:: Value of configuration option if there is one
# nil:: Otherwise
def [](config_option)
- init
@settings_values[config_option]
end
protected
@@ -171,11 +172,10 @@
#
# === Return
# res(Object):: Configuration setting value or setter return value if
# arguments
def method_missing(meth, *args)
- init
num_args = args.length
res = nil
if num_args > 0
meth = $1.to_sym unless (meth.to_s =~ /(.+)=$/).nil?
value = num_args == 1 ? args[0] : args
@@ -187,14 +187,18 @@
end
end
res || @settings_values[meth]
end
- # Initialize configuration settings hash
+ # Initialize configuration settings hash and index
#
+ # === Parameters
+ # index(Fixnum):: Unique index of configurators in rconf file
+ #
# === Return
# true:: Always return true
- def init
+ def initialize(index)
+ @index = index
@settings_values ||= Hash.new
true
end
end