Sha256: 3ac7c7a37556ef182ab788c13b96e4a95174a4e9b0766d8f62b9d5cf88fed596

Contents?: true

Size: 965 Bytes

Versions: 27

Compression:

Stored size: 965 Bytes

Contents

module Hyperloop
# configuration utility
  class << self
    def initialized_blocks
      @initialized_blocks ||= []
    end

    def reset_blocks
      @reset_blocks ||= []
    end

    def configuration
      reset_blocks.each(&:call)
      yield self
      initialized_blocks.each(&:call)
    end

    def define_setting(name, default = nil, &block)
      class_variable_set("@@#{name}", default)

      define_class_method "#{name}=" do |value|
        class_variable_set("@@#{name}", value)
        block.call value if block
        value
      end

      define_class_method name do
        class_variable_get("@@#{name}")
      end
    end


    def on_config_reset &block
      reset_blocks << block
    end

    def on_config_initialized &block
      initialized_blocks << block
    end

    private

    def define_class_method(name, &block)
      (class << self; self; end).instance_eval do
        define_method name, &block
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hyperloop-config-0.99.6 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.5 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.4 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.3 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.2 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.1 lib/hyperloop/config_settings.rb
hyperloop-config-0.99.0 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap28 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap27 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap26 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap25 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap24 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap23 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap22 lib/hyperloop/config_settings.rb
hyperloop-config-1.0.0.lap21 lib/hyperloop/config_settings.rb
hyperloop-config-0.9.11 lib/hyperloop/config_settings.rb
hyperloop-config-0.9.10 lib/hyperloop/config_settings.rb
hyperloop-config-0.9.9 lib/hyperloop/config_settings.rb
hyperloop-config-0.9.8 lib/hyperloop/config_settings.rb
hyperloop-config-0.9.7 lib/hyperloop/config_settings.rb