mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
CookieJar should prefer composition over inheritance
This commit is contained in:
parent
9f765f4e09
commit
0ca69ca65f
1 changed files with 10 additions and 6 deletions
|
@ -83,7 +83,7 @@ module ActionDispatch
|
||||||
# Raised when storing more than 4K of session data.
|
# Raised when storing more than 4K of session data.
|
||||||
class CookieOverflow < StandardError; end
|
class CookieOverflow < StandardError; end
|
||||||
|
|
||||||
class CookieJar < Hash #:nodoc:
|
class CookieJar #:nodoc:
|
||||||
|
|
||||||
# This regular expression is used to split the levels of a domain.
|
# This regular expression is used to split the levels of a domain.
|
||||||
# The top level domain can be any string without a period or
|
# The top level domain can be any string without a period or
|
||||||
|
@ -116,8 +116,7 @@ module ActionDispatch
|
||||||
@host = host
|
@host = host
|
||||||
@secure = secure
|
@secure = secure
|
||||||
@closed = false
|
@closed = false
|
||||||
|
@cookies = {}
|
||||||
super()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :closed
|
attr_reader :closed
|
||||||
|
@ -126,7 +125,12 @@ module ActionDispatch
|
||||||
|
|
||||||
# Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
|
# Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
|
||||||
def [](name)
|
def [](name)
|
||||||
super(name.to_s)
|
@cookies[name.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(other_hash)
|
||||||
|
@cookies.update other_hash
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_options(options) #:nodoc:
|
def handle_options(options) #:nodoc:
|
||||||
|
@ -159,7 +163,7 @@ module ActionDispatch
|
||||||
options = { :value => value }
|
options = { :value => value }
|
||||||
end
|
end
|
||||||
|
|
||||||
value = super(key.to_s, value)
|
value = @cookies[key.to_s] = value
|
||||||
|
|
||||||
handle_options(options)
|
handle_options(options)
|
||||||
|
|
||||||
|
@ -176,7 +180,7 @@ module ActionDispatch
|
||||||
|
|
||||||
handle_options(options)
|
handle_options(options)
|
||||||
|
|
||||||
value = super(key.to_s)
|
value = @cookies.delete(key.to_s)
|
||||||
@delete_cookies[key] = options
|
@delete_cookies[key] = options
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue