Sha256: a705e645d5d2fadbcaab675ac7094a81563b4375e4223f111f9d6345da1393e9

Contents?: true

Size: 966 Bytes

Versions: 12

Compression:

Stored size: 966 Bytes

Contents

module Hyperstack
# 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

12 entries across 12 versions & 1 rubygems

Version Path
hyperstack-config-1.0.alpha1.8 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.7 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.6 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.5 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.4 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.3 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.2 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1.1 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.0.pre.alpha1 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.alpha1 lib/hyperstack/config_settings.rb
hyperstack-config-1.0.pre.alpha1 lib/hyperstack/config_settings.rb
hyperstack-config-0.1 lib/hyperstack/config_settings.rb