Sha256: badacf52bd72f5e89a867e01fb1ef1e2a7c95074df5f6bff2b2f87409c0b3d8d

Contents?: true

Size: 769 Bytes

Versions: 5

Compression:

Stored size: 769 Bytes

Contents

module HyperMesh
  # configuration utility
  module Configuration

    def configuration
      config_reset
      yield self
      config_initialized
    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 config_reset
      raise "must implement"
    end

    def config_initialized
    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

5 entries across 5 versions & 1 rubygems

Version Path
hyper-mesh-0.5.3 lib/synchromesh/configuration.rb
hyper-mesh-0.5.2 lib/synchromesh/configuration.rb
hyper-mesh-0.5.1 lib/synchromesh/configuration.rb
hyper-mesh-0.5.0 lib/synchromesh/configuration.rb
hyper-mesh-0.4.0 lib/synchromesh/configuration.rb