Sha256: 1465e47b9c947464d73dfff12b8a27c56700a6c3c54382d4b1ac5f7c52fd51f0

Contents?: true

Size: 842 Bytes

Versions: 8

Compression:

Stored size: 842 Bytes

Contents

module Gumdrop::Util

  module Configurable
    module ClassMethods

      def config_accessor(*keys)
        keys.each do |key|
          class_eval <<-RUBY, __FILE__, __LINE__ + 1
            def #{key}; config[#{key.inspect}]; end
            def #{key}=(value); config[#{key.inspect}]= value; end
          RUBY
        end
      end

    end
    
    module InstanceMethods

      def config
        @config ||= HashObject.new
      end

      def configure(&block)
        if block.arity == 1
          block.call config
        else
          config.instance_eval &block
        end
        config_did_change
      end

      def config_did_change
        # Override me!
      end

    end
    
    def self.included(receiver)
      receiver.extend         ClassMethods
      receiver.send :include, InstanceMethods
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gumdrop-1.1.3 lib/gumdrop/util/configurable.rb
gumdrop-1.1.2 lib/gumdrop/util/configurable.rb
gumdrop-1.1.1 lib/gumdrop/util/configurable.rb
gumdrop-1.1.0 lib/gumdrop/util/configurable.rb
gumdrop-1.0.3 lib/gumdrop/util/configurable.rb
gumdrop-1.0.2 lib/gumdrop/util/configurable.rb
gumdrop-1.0.1 lib/gumdrop/util/configurable.rb
gumdrop-1.0.0 lib/gumdrop/util/configurable.rb