Sha256: 9a592f5592c65ccadd7b7c86cca08aadf6a1c83e41c918562992b059d60cca20

Contents?: true

Size: 714 Bytes

Versions: 3

Compression:

Stored size: 714 Bytes

Contents

require 'http/cookie_jar'
begin
  require 'psych'
rescue LoadError
end
require 'yaml'

# YAMLSaver saves and loads cookies in the YAML format.
class HTTP::CookieJar::YAMLSaver < HTTP::CookieJar::AbstractSaver
  def save(io, jar)
    YAML.dump(@session ? jar.to_a : jar.reject(&:session?), io)
  end

  def load(io, jar)
    begin
      data = YAML.load(io)
    rescue ArgumentError
      @logger.warn "unloadable YAML cookie data discarded" if @logger
      return
    end

    unless data.instance_of?(Array)
      @logger.warn "incompatible YAML cookie data discarded" if @logger
      return
    end

    data.each { |cookie|
      jar.add(cookie)
    }
  end

  private

  def default_options
    {}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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