Sha256: dad2796c7e7b2caa1975cab457a009f85e08f998353343a767e77a7d1a3769fd

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

class Cookie

  # Models a transient, new cookie on the server that can be serialized
  # into an HTTP 'Set-Cookie' header
  class Header

    include Concord.new(:cookie, :attributes)
    include Adamantium::Flat

    def self.build(name, value, attributes)
      new(Cookie.new(name, value), attributes)
    end

    def initialize(cookie, attributes = Attribute::Set::EMPTY)
      super
    end

    def with_domain(domain)
      with_attribute(Attribute::Domain.new(domain))
    end

    def with_path(path)
      with_attribute(Attribute::Path.new(path))
    end

    def with_max_age(seconds)
      with_attribute(Attribute::MaxAge.new(seconds))
    end

    def with_expires(time)
      with_attribute(Attribute::Expires.new(time))
    end

    def secure
      with_attribute(Attribute::Secure.instance)
    end

    def http_only
      with_attribute(Attribute::HttpOnly.instance)
    end

    def delete
      new(Empty.new(cookie.name), attributes.merge(Attribute::Expired))
    end

    def to_s
      "#{cookie}#{attributes}"
    end
    memoize :to_s

    private

    def with_attribute(attribute)
      new(cookie, attributes.merge(attribute))
    end

    def new(cookie, attributes)
      self.class.new(cookie, attributes)
    end

  end # class Header
end # class Cookie

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
majoun-0.0.4 lib/cookie/header.rb
majoun-0.0.3 lib/cookie/header.rb