smart_cookie_store 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -1
- data/Rakefile +1 -1
- data/lib/smart_cookie_store.rb +17 -13
- metadata +12 -5
data/README.md
CHANGED
|
@@ -20,10 +20,23 @@ session is not empty.
|
|
|
20
20
|
Usage
|
|
21
21
|
=====
|
|
22
22
|
|
|
23
|
+
Install as a gem:
|
|
24
|
+
-----------------
|
|
25
|
+
|
|
26
|
+
gem install smart_cookie_store
|
|
27
|
+
|
|
28
|
+
And add it to your `config/environment.rb`:
|
|
29
|
+
|
|
30
|
+
config.gem "smart_cookie_store"
|
|
31
|
+
|
|
23
32
|
Install as a plugin:
|
|
33
|
+
--------------------
|
|
24
34
|
|
|
25
35
|
script/plugin install git://github.com/msales/smart_cookie_store.git
|
|
26
|
-
|
|
36
|
+
|
|
37
|
+
Configuration
|
|
38
|
+
-------------
|
|
39
|
+
|
|
27
40
|
The configure your app to use the new `SmartCookieStore`:
|
|
28
41
|
|
|
29
42
|
ActionController::Base.session_store = :smart_cookie_store
|
data/Rakefile
CHANGED
|
@@ -11,7 +11,7 @@ PKG_FILES = FileList[
|
|
|
11
11
|
|
|
12
12
|
spec = Gem::Specification.new do |s|
|
|
13
13
|
s.name = "smart_cookie_store"
|
|
14
|
-
s.version = "0.0.
|
|
14
|
+
s.version = "0.0.2"
|
|
15
15
|
s.author = "Urban Hafner"
|
|
16
16
|
s.email = "urban@bettong.net"
|
|
17
17
|
s.homepage = "http://github.com/msales/smart_cookie_store"
|
data/lib/smart_cookie_store.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class SmartCookieStore < ActionController::Session::CookieStore
|
|
2
2
|
|
|
3
|
-
SH = ActionController::Session::AbstractStore::SessionHash
|
|
4
3
|
def call(env)
|
|
5
|
-
|
|
4
|
+
sh = ActionController::Session::AbstractStore::SessionHash
|
|
5
|
+
env[ENV_SESSION_KEY] = sh.new(self, env)
|
|
6
6
|
env[ENV_SESSION_OPTIONS_KEY] = @default_options.dup
|
|
7
7
|
|
|
8
8
|
status, headers, body = @app.call(env)
|
|
@@ -10,26 +10,30 @@ class SmartCookieStore < ActionController::Session::CookieStore
|
|
|
10
10
|
session_data = env[ENV_SESSION_KEY]
|
|
11
11
|
options = env[ENV_SESSION_OPTIONS_KEY]
|
|
12
12
|
|
|
13
|
-
if !session_data.is_a?(
|
|
14
|
-
session_data.send(:load!) if session_data.is_a?(
|
|
13
|
+
if !session_data.is_a?(sh) || session_data.send(:loaded?) || options[:expire_after]
|
|
14
|
+
session_data.send(:load!) if session_data.is_a?(sh) && !session_data.send(:loaded?)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
cookie = Hash.new
|
|
17
|
+
|
|
18
|
+
session_keys = session_data.keys.reject {|k| k == :session_id }
|
|
19
|
+
if session_keys.empty? || session_keys.all? {|k| session_data[k].blank?}
|
|
20
|
+
cookie[:value] = ''
|
|
21
|
+
cookie[:expires] = Time.at(0)
|
|
22
|
+
else
|
|
17
23
|
marshaled_session_data = marshal(session_data.to_hash)
|
|
18
24
|
|
|
19
25
|
raise CookieOverflow if marshaled_session_data.size > MAX
|
|
20
26
|
|
|
21
|
-
cookie = Hash.new
|
|
22
27
|
cookie[:value] = marshaled_session_data
|
|
23
28
|
unless options[:expire_after].nil?
|
|
24
29
|
cookie[:expires] = Time.now + options[:expire_after]
|
|
25
30
|
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
31
|
+
end
|
|
32
|
+
cookie = build_cookie(@key, cookie.merge(options))
|
|
33
|
+
unless headers[HTTP_SET_COOKIE].blank?
|
|
34
|
+
headers[HTTP_SET_COOKIE] << "\n#{cookie}"
|
|
35
|
+
else
|
|
36
|
+
headers[HTTP_SET_COOKIE] = cookie
|
|
33
37
|
end
|
|
34
38
|
end
|
|
35
39
|
|
metadata
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_cookie_store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.0.2
|
|
5
10
|
platform: ruby
|
|
6
11
|
authors:
|
|
7
12
|
- Urban Hafner
|
|
@@ -9,7 +14,7 @@ autorequire:
|
|
|
9
14
|
bindir: bin
|
|
10
15
|
cert_chain: []
|
|
11
16
|
|
|
12
|
-
date: 2010-
|
|
17
|
+
date: 2010-04-28 00:00:00 +02:00
|
|
13
18
|
default_executable:
|
|
14
19
|
dependencies: []
|
|
15
20
|
|
|
@@ -39,18 +44,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
39
44
|
requirements:
|
|
40
45
|
- - ">="
|
|
41
46
|
- !ruby/object:Gem::Version
|
|
47
|
+
segments:
|
|
48
|
+
- 0
|
|
42
49
|
version: "0"
|
|
43
|
-
version:
|
|
44
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
51
|
requirements:
|
|
46
52
|
- - ">="
|
|
47
53
|
- !ruby/object:Gem::Version
|
|
54
|
+
segments:
|
|
55
|
+
- 0
|
|
48
56
|
version: "0"
|
|
49
|
-
version:
|
|
50
57
|
requirements: []
|
|
51
58
|
|
|
52
59
|
rubyforge_project:
|
|
53
|
-
rubygems_version: 1.3.
|
|
60
|
+
rubygems_version: 1.3.6
|
|
54
61
|
signing_key:
|
|
55
62
|
specification_version: 3
|
|
56
63
|
summary: Enhanced Rails CookieStore
|