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

Version Path
sunspot-2.7.1 lib/light_config.rb
sunspot-2.7.0 lib/light_config.rb
sunspot-2.6.0 lib/light_config.rb
sunspot-2.5.0 lib/light_config.rb
sunspot-2.4.0 lib/light_config.rb
sunspot-2.3.0 lib/light_config.rb
sunspot-2.2.8 lib/light_config.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/light_config.rb
sunspot-2.2.7 lib/light_config.rb
sunspot-2.2.6 lib/light_config.rb
sunspot-2.2.5 lib/light_config.rb
sunspot-2.2.4 lib/light_config.rb
sunspot-2.2.3 lib/light_config.rb
sunspot-2.2.2 lib/light_config.rb
sunspot-2.2.1 lib/light_config.rb
sunspot-2.2.0 lib/light_config.rb
Chrononaut-sunspot-client-0.9.4 lib/light_config.rb
UnderpantsGnome-sunspot-0.9.1.1 lib/light_config.rb
UnderpantsGnome-sunspot-0.9.8.1 lib/light_config.rb
benjaminkrause-sunspot-0.9.7 lib/light_config.rb