Sha256: 679c3ab4f48bc84e2125705f752b0c08340e6ca0e84182031bda2c0dba3b1289

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'http/cookie_jar'

class HTTP::CookieJar::AbstractSaver
  class << self
    @@class_map = {}

    # Gets an implementation class by the name, optionally trying to
    # load "http/cookie_jar/*_saver" if not found.  If loading fails,
    # KeyError is raised.
    def implementation(symbol)
      @@class_map.fetch(symbol)
    rescue KeyError
      begin
        require 'http/cookie_jar/%s_saver' % symbol
        @@class_map.fetch(symbol)
      rescue LoadError, KeyError => e
        raise KeyError, 'cookie saver unavailable: %s' % symbol.inspect
      end
    end

    def inherited(subclass)
      @@class_map[class_to_symbol(subclass)] = subclass
    end

    def class_to_symbol(klass)
      klass.name[/[^:]+?(?=Saver$|$)/].downcase.to_sym
    end
  end

  def default_options
    {}
  end
  private :default_options

  def initialize(options = nil)
    options ||= {}
    @logger  = options[:logger]
    @session = options[:session]
    # Initializes each instance variable of the same name as option
    # keyword.
    default_options.each_pair { |key, default|
      instance_variable_set("@#{key}", options.key?(key) ? options[key] : default)
    }
  end

  def save(io, jar)
    raise
  end

  def load(io, jar)
    raise
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
http-cookie-0.1.1 lib/http/cookie_jar/abstract_saver.rb
http-cookie-0.1.0 lib/http/cookie_jar/abstract_saver.rb