Sha256: 17c7491a006211bc350841484f823448a11eb601744602b4c9cf2fced2cfd933

Contents?: true

Size: 725 Bytes

Versions: 2

Compression:

Stored size: 725 Bytes

Contents

require 'populus'

module Populus
  class Configuration
    def initialize
      @pool = {}
    end

    def set(key, value)
      true_value = case value
                   when Proc
                     value
                   else
                     lambda { value }
                   end
      self.define_singleton_method key do
        @pool[key] || (
          @pool[key] = true_value.call
        )
      end
    end

    def method_missing(meth, *args)
      raise NameError, "Populus::Configuration value #{meth} is not yet defined"
    end
  end

  def self.config(&config_block)
    @_config ||= Configuration.new
    if block_given?
      @_config.instance_eval(&config_block)
    end
    @_config
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
populus-0.0.4 lib/populus/configuration.rb
populus-0.0.3 lib/populus/configuration.rb