Sha256: 01c7e6b0aaa03192509280659b6ded2e8a15c5e0bd7fde52accaaa4e3a643b32
Contents?: true
Size: 1.02 KB
Versions: 113
Compression:
Stored size: 1.02 KB
Contents
module LightConfig class Configuration def initialize(&block) @properties = {} ::LightConfig::Builder.new(self).instance_eval(&block) singleton = (class <<self; self; end) @properties.keys.each do |property| singleton.module_eval do define_method property do @properties[property] end define_method "#{property}=" do |value| @properties[property] = value end end end end end class Builder def initialize(configuration) @configuration = configuration end def method_missing(method, *args, &block) raise ArgumentError("wrong number of arguments(#{args.length} for 1)") unless args.length < 2 value = if block then ::LightConfig::Configuration.new(&block) else args.first end @configuration.instance_variable_get(:@properties)[method] = value end end class <<self def build(&block) LightConfig::Configuration.new(&block) end end end
Version data entries
113 entries across 113 versions & 20 rubygems