Module: MJ::Configuration::Configurable
- Included in:
- BuildTool::Application, BuildTool::BuildSystem::BaseConfiguration, BuildTool::CTagsConfiguration, BuildTool::MakeConfiguration, BuildTool::ModuleConfiguration, BuildTool::ModuleRegistry, BuildTool::VCS::BaseConfiguration
- Defined in:
- lib/kde-build/configuration.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
129 130 131 132 |
# File 'lib/kde-build/configuration.rb', line 129 def self.included( klass ) klass.extend( ClassMethods ) klass.send( :class_variable_set, '@@__options__', Hash.new ) end |
Instance Method Details
#parse(val) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/kde-build/configuration.rb', line 187 def parse( val ) # If it is a array we expect it to only contain hashes if val.instance_of?( Array ) val.each { |i| parse( i ) } elsif val.instance_of?( Hash ) val.each_pair { |k, v| begin # puts "#{self.class}.#{k} = #{v}" send "#{Option.sanitize k}=", v rescue NameError => e $log.warn( "Unknown option '#{k}' for #{self.class} in #{self.name}: #{e}" ) end } else raise Exception, "FIXME" end self end |
#set(key, val) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/kde-build/configuration.rb', line 159 def set( key, val ) begin # puts "Options = #{self.class.options.inspect}" self.send( "#{Option.sanitize( key )}=", val ) rescue BuildTool::VCS::UnknownVcsError => e $log.warn( "Unknown vcs '#{key}' configured for #{self.name}:#{self.class}" ) raise e rescue NameError => e $log.warn( "Unknown option #{key} configured for #{self.name}:#{self.class}" ) raise e rescue Exception => e $log.warn( "Caught exception #{e.} for #{self.inspect}:#{self.class} while setting #{key} to #{val.inspect}" ) raise e end end |
#validate ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/kde-build/configuration.rb', line 175 def validate begin self.class..each_pair do |name, opt| opt.validate( self.values[opt.attribute] ) end rescue ConfigurationError => e $log.error( "Validation for #{self.class} (#{self.to_s}) failed: #{e}" ) puts e.backtrace if $verbose raise e end end |
#values ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/kde-build/configuration.rb', line 150 def values return @values if @values @values = Hash.new self.class..each_pair do |name, opt| @values[name] = opt.default end @values end |