diff options
author | Rizwan Reza <rizwanreza@gmail.com> | 2010-06-11 13:50:09 +0430 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-11 16:34:53 +0200 |
commit | b602ce61919afd0797057942f74bdeb9eae65d6b (patch) | |
tree | 3a857c751af56a05bb2f09708ff9e3b4def17203 /actionpack/lib | |
parent | 6148b2dd738ff422b80502935857ecaec2161a23 (diff) | |
download | rails-b602ce61919afd0797057942f74bdeb9eae65d6b.tar.gz rails-b602ce61919afd0797057942f74bdeb9eae65d6b.tar.bz2 rails-b602ce61919afd0797057942f74bdeb9eae65d6b.zip |
Refactored duplication into a separate method. Dropped class variable.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 2b3538af25..d69ba39728 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -78,16 +78,18 @@ module ActionDispatch def self.build(request) secret = request.env[TOKEN_KEY] - @@host = request.env["HTTP_HOST"] - new(secret).tap do |hash| + host = request.env["HTTP_HOST"] + + new(secret, host).tap do |hash| hash.update(request.cookies) end end - def initialize(secret=nil) + def initialize(secret = nil, host = nil) @secret = secret @set_cookies = {} @delete_cookies = {} + @host = host super() end @@ -97,6 +99,15 @@ module ActionDispatch super(name.to_s) end + def handle_options(options) #:nodoc: + options[:path] ||= "/" + + if options[:domain] == :all + @host =~ DOMAIN_REGEXP + options[:domain] = ".#{$2}.#{$3}" + end + end + # Sets the cookie named +name+. The second argument may be the very cookie # value, or a hash of options as documented above. def []=(key, options) @@ -110,13 +121,8 @@ module ActionDispatch value = super(key.to_s, value) - options[:path] ||= "/" - - if options[:domain] == :all - @@host =~ DOMAIN_REGEXP - options[:domain] = ".#{$2}.#{$3}" - end - + handle_options(options) + @set_cookies[key] = options @delete_cookies.delete(key) value @@ -127,12 +133,8 @@ module ActionDispatch # an options hash to delete cookies with extra data such as a <tt>:path</tt>. def delete(key, options = {}) options.symbolize_keys! - options[:path] ||= "/" - if options[:domain] == :all - @@host =~ DOMAIN_REGEXP - options[:domain] = ".#{$2}.#{$3}" - end + handle_options(options) value = super(key.to_s) @delete_cookies[key] = options |