Sha256: 687536f327ce9e655623383f1e243890c0e92c9077a80dc201a89dc9ce12f94a

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'forwardable'
require 'wayback/error/configuration_error'

module Wayback
  module Configurable
    extend Forwardable
    attr_accessor :endpoint, :endpoint_path, :json_endpoint, :json_endpoint_path, :connection_options, :identity_map, :middleware
    def_delegator :options, :hash

    class << self

      def keys
        @keys ||= [
          :endpoint,
          :endpoint_path,
          :json_endpoint,
          :json_endpoint_path,
          :connection_options,
          :identity_map,
          :middleware
        ]
      end

    end

    # Convenience method to allow configuration options to be set in a block
    #
    # @raise [Wayback::Error::ConfigurationError] Error is raised when supplied
    #   wayback credentials are not a String or Symbol.
    def configure
      yield self
      self
    end

    def reset!
      Wayback::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", Wayback::Default.options[key])
      end
      self
    end
    alias setup reset!

  private

    # @return [Hash]
    def options
      Hash[Wayback::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wayback-0.3.1 lib/wayback/configurable.rb