Module: RightConf::Configurator
- Includes:
- ProgressReporter
- Included in:
- BundlerConfigurator, MercurialConfigurator, PackagesConfigurator, PassengerConfigurator, RubyConfigurator
- Defined in:
- lib/rconf/configurator.rb
Overview
Configurator mixin, defines DSL and common validation method
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Extend base class with ClassMethods module methods.
Instance Method Summary collapse
-
#[](config_option) ⇒ Object
Get value of configuration option.
-
#post_process ⇒ Object
Called even if configuration is already done for steps that must always happen, do nothing by default.
-
#run(*args) ⇒ Object
Run configurator for current platform.
-
#signature ⇒ Object
Calculate unique SHA for current settings.
-
#validate ⇒ Object
Check whether configurator has values for all required settings.
Methods included from ProgressReporter
report_to_file, report_to_stdout
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object (protected)
DSL implementation, set settings value if arguments, get it otherwise.
Parameters
- meth(Symbol)
-
Method symbol
- args(Array)
-
List of arguments
Return
- res(Object)
-
Configuration setting value or setter return value if arguments
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rconf/configurator.rb', line 175 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 method_name = meth.id2name if self.public_methods.include?("#{method_name}=") res = self.send("#{method_name}=", value) else res = @settings_values[meth] = value end end res || @settings_values[meth] end |
Class Method Details
.included(base) ⇒ Object
Extend base class with ClassMethods module methods
Parameters
- base(Object)
-
Object including module
90 91 92 |
# File 'lib/rconf/configurator.rb', line 90 def self.included(base) base.__send__(:extend, ClassMethods) end |
Instance Method Details
#[](config_option) ⇒ Object
Get value of configuration option
Parameters
- config_option(Symbol)
-
Configuration option to return
Returns
- value
-
Value of configuration option if there is one
- nil
-
Otherwise
159 160 161 162 |
# File 'lib/rconf/configurator.rb', line 159 def [](config_option) init @settings_values[config_option] end |
#post_process ⇒ Object
Called even if configuration is already done for steps that must always happen, do nothing by default
Return
- true
-
Always return true
137 138 139 |
# File 'lib/rconf/configurator.rb', line 137 def post_process true end |
#run(*args) ⇒ Object
Run configurator for current platform
Parameters
- args
-
Pass-through arguments, given to platform specific implementation
Return
- true
-
Always return true
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rconf/configurator.rb', line 121 def run(*args) init sha = Profile.configurator_signature(self.class.key) sig = signature if sha != sig Platform.dispatch(*args) { :run } Profile.set_configurator_signature(self.class.key, sig) end true end |
#signature ⇒ Object
Calculate unique SHA for current settings
Return
- sha(String)
-
SHA for current settings
145 146 147 148 149 |
# File 'lib/rconf/configurator.rb', line 145 def signature blob = VERSION blob = @settings_values.inject(blob) { |b, (k, v)| b += "#{k}:#{v};" } if @settings_values sha = Digest::SHA1.hexdigest(blob) end |
#validate ⇒ Object
Check whether configurator has values for all required settings
Return
- nil
-
If settings are valid for this configurator
- error(String)
-
Error message otherwise
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rconf/configurator.rb', line 99 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 when 1 then "Required setting #{missing.first} is " else "Required settings #{missing.join(', ')} are " end error += "missing for configuration section '#{self.class.key}'" if error error end |