tld-cookies 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +53 -0
- data/Rakefile +2 -0
- data/lib/tld-cookies.rb +2 -0
- data/lib/tld-cookies/cookie_jar.rb +23 -0
- data/lib/tld-cookies/top_level_domain_cookie_jar.rb +32 -0
- data/lib/tld-cookies/version.rb +5 -0
- data/tld-cookies.gemspec +25 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Top Level Domain Cookies
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Top level domain cookie jar for Rails 3.
|
6
|
+
|
7
|
+
== Summary
|
8
|
+
|
9
|
+
When you are using subdomains with your Rails 3, sometimes you need to set the cookies on the top level domain. One option is set the default domain in config/initializers/session_store.rb.
|
10
|
+
|
11
|
+
Rails.application.config.session_store :cookie_store, :key => '_app_name_session', :domain => :all
|
12
|
+
|
13
|
+
The other option is for all the cookies to be written on the current location (subdomain included) and specify cookies that need need to written on the top level domain individually. This case is where this gem can be useful.
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
+TopLevelDomainCookieJar+ is used in a very much like the +PermanentCookieJar+. It is a write only cookie jar. The cookies are accessed through the normal accessor.
|
18
|
+
|
19
|
+
Write a top level domain cookie:
|
20
|
+
|
21
|
+
cookies.tld[:all_access_cookie] = "All subdomains can read this."
|
22
|
+
|
23
|
+
Read the cookie:
|
24
|
+
|
25
|
+
cookies[:all_access_cookie] # All subdomains can read this.
|
26
|
+
|
27
|
+
You can chain the top level domain cookie jar:
|
28
|
+
|
29
|
+
cookies.tld.signed[:tamper_proof_all_access_cookie] = "All subdomains can read this."
|
30
|
+
cookies.signed[:tamper_proof_all_access_cookie] # All subdomains can read this.
|
31
|
+
|
32
|
+
== License
|
33
|
+
|
34
|
+
Copyright (c) 2011 Les Fletcher
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
"Software"), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
50
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
51
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
52
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
53
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/tld-cookies.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Tld
|
2
|
+
module Cookies
|
3
|
+
module CookieJar
|
4
|
+
# Returns a jar that'll automatically set the assigned cookies to the top level domain, regardless of if there
|
5
|
+
# is a subdomain present or not. Example:
|
6
|
+
#
|
7
|
+
# cookies.tld[:prefers_open_id] = true
|
8
|
+
# # => Set-Cookie: prefers_open_id=true; path=/; expires=Sun, 27-Mar-2011 03:24:16 GMT
|
9
|
+
#
|
10
|
+
# This jar is only meant for writing. You'll read tld cookies through the regular accessor.
|
11
|
+
#
|
12
|
+
# This jar allows chaining with other jars as well, so you can set tld, signed cookies. Examples:
|
13
|
+
#
|
14
|
+
# cookies.tld.signed[:remember_me] = current_user.id
|
15
|
+
# # => Set-Cookie: remember_me=BAhU--848956038e692d7046deab32b7131856ab20e14e; path=/; expires=Sun, 27-Mar-2011 03:24:16 GMT
|
16
|
+
def tld
|
17
|
+
@tld ||= TopLevelDomainCookieJar.new(self, @secret)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionDispatch::Cookies::CookieJar.send(:include, Tld::Cookies::CookieJar)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Tld
|
2
|
+
module Cookies
|
3
|
+
# A cookie jar that always sets the +domain+ to +:all+.
|
4
|
+
class TopLevelDomainCookieJar < ActionDispatch::Cookies::CookieJar
|
5
|
+
def initialize(parent_jar, secret)
|
6
|
+
@parent_jar, @secret = parent_jar, secret
|
7
|
+
end
|
8
|
+
|
9
|
+
def []=(key, options)
|
10
|
+
if options.is_a?(Hash)
|
11
|
+
options.symbolize_keys!
|
12
|
+
else
|
13
|
+
options = { :value => options }
|
14
|
+
end
|
15
|
+
|
16
|
+
options[:domain] = :all
|
17
|
+
|
18
|
+
@parent_jar[key] = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(key, options = {})
|
22
|
+
@parent_jar.delete(key, options.merge({ :domain => :all }))
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method, *arguments, &block)
|
26
|
+
@parent_jar.send(method, *arguments, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ActionDispatch::Cookies.send(:include, Tld::Cookies)
|
data/tld-cookies.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tld-cookies/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tld-cookies"
|
7
|
+
s.version = Tld::Cookies::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Les Fletcher"]
|
10
|
+
s.email = ["les.fletcher@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Top Level Domain cookies for Rails 3}
|
13
|
+
s.description = %q{Add a TLD cookie jar for Rails 3 that can be chained with permanent and signed cookies}
|
14
|
+
|
15
|
+
s.rubyforge_project = "tld-cookies"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.has_rdoc = true
|
23
|
+
|
24
|
+
s.add_dependency('rails', '~> 3.0.0')
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tld-cookies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Les Fletcher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-03 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Add a TLD cookie jar for Rails 3 that can be chained with permanent and signed cookies
|
28
|
+
email:
|
29
|
+
- les.fletcher@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- lib/tld-cookies.rb
|
42
|
+
- lib/tld-cookies/cookie_jar.rb
|
43
|
+
- lib/tld-cookies/top_level_domain_cookie_jar.rb
|
44
|
+
- lib/tld-cookies/version.rb
|
45
|
+
- tld-cookies.gemspec
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: ""
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: tld-cookies
|
70
|
+
rubygems_version: 1.5.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Top Level Domain cookies for Rails 3
|
74
|
+
test_files: []
|
75
|
+
|