lib/rconf/overrides_language.rb in rconf-0.10.1 vs lib/rconf/overrides_language.rb in rconf-1.0.0

- old
+ new

@@ -15,18 +15,22 @@ class OverridesLanguage # Path to overrides file OVERRIDES_FILE = File.join(ENV['HOME'], '.rconf_overrides') + # Lexical token used to indicate that the value of an overridden configurator attribute should literally + # be nil, not the string "nil" or "none". + NIL_LITERAL = /^(nil|none)$/ + + # Return override for given configurator setting if any # # === Parameters # key(String):: Configurator key - # setting(String):: Setting name # # === Return - # value(String||Nil):: Override value if any, nil otherwise + # value(String||Nil):: Override values if any, nil otherwise def self.overrides_for(key) self.load unless @overrides @overrides && @overrides[key] || {} end @@ -83,15 +87,22 @@ source.split("\n").each do |o| operands = o.gsub(/\s+/, '').split('=') if operands.size != 2 raise "Invalid syntax '#{o}', must be of the form 'key.setting=value'" end + if operands[1].start_with?('"') || operands[1].start_with?("'") + # Quoted string value = operands[1] + elsif operands[1] =~ NIL_LITERAL + # Literal nil + value = 'nil' else + # Anything else: assume unquoted string value = "'#{operands[1]}'" end + overrides.instance_eval("@#{operands[0]}=#{value}") end rescue Exception => e @overrides = nil @parse_error = e @@ -140,6 +151,5 @@ [klass, code] end end end -