Skip to content

Commit

Permalink
CookieStore extends Hash instead of delegating
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskite committed Feb 6, 2010
1 parent 01c1e74 commit 5646b34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions anemone.gemspec
Expand Up @@ -20,6 +20,7 @@ spec = Gem::Specification.new do |s|
README.rdoc
bin/anemone
lib/anemone.rb
lib/anemone/cookie_store.rb
lib/anemone/core.rb
lib/anemone/http.rb
lib/anemone/page.rb
Expand Down
16 changes: 5 additions & 11 deletions lib/anemone/cookie_store.rb
@@ -1,15 +1,9 @@
require 'forwardable'

module Anemone
class CookieStore
extend Forwardable

def_delegators :@cookies, :empty?

attr_reader :cookies
class CookieStore < Hash

def initialize(cookies = nil)
@cookies = cookies || {}
super
cookies.each { |key, value| self[key] = value } if cookies
end

def merge!(set_cookie_str)
Expand All @@ -18,11 +12,11 @@ def merge!(set_cookie_str)
key, value = pair.strip.split('=')
acc[key] = value if key
end
@cookies.merge! cookie_hash
super(cookie_hash)
end

def to_s
@cookies.map { |name, value| "#{name}=#{value}" }.join(';')
self.map { |name, value| "#{name}=#{value}" }.join(';')
end

end
Expand Down
11 changes: 11 additions & 0 deletions spec/cookie_store_spec.rb
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/spec_helper'

module Anemone
describe CookieStore do

it "should start out empty if no cookies are specified" do
CookieStore.new.empty?.should be true
end

end
end

0 comments on commit 5646b34

Please sign in to comment.