lib/loquacious/configuration.rb in TwP-loquacious-1.0.0 vs lib/loquacious/configuration.rb in TwP-loquacious-1.1.0

- old
+ new

@@ -129,10 +129,32 @@ end self end + # Provides hash accessor notation for configuration values. + # + # config = Configuration.for('app') { + # port 1234 + # } + # config[:port] #=> 1234 + # config.port #=> 1234 + # + def []( key ) + self.__send__(key) + end + + # Provides hash accessor notation for configuration values. + # + # config = Configuration.for('app') + # config[:port] = 8808 + # config.port #=> 8808 + # + def []=( key, value ) + self.__send__(key, value) + end + # Implementation of a doman specific language for creating configuration # objects. Blocks of code are evaluted by the DSL which returns a new # configuration object. # class DSL @@ -168,11 +190,13 @@ # attribute will be a nested configuration object. # def method_missing( method, *args, &block ) m = method.to_s.delete('=').to_sym - opts = args.last.instance_of?(Hash) ? args.pop : {} - self.desc(opts[:desc]) if opts.has_key? :desc + if args.length > 1 + opts = args.last.instance_of?(Hash) ? args.pop : {} + self.desc(opts[:desc]) if opts.has_key? :desc + end __config.__send__(m, *args, &block) __config.__desc[m] = @description @description = nil