couchrest_session_store 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # CouchRest Session Store #
2
2
 
3
- A simple session store based on CouchRest Model - nothing more.
3
+ A simple session store based on CouchRest Model.
4
+
5
+ ## Options ##
6
+
7
+ * marhal_data: (_defaults true_) - if set to false session data will be stored directly in the couch document. Otherwise it's marshalled and base64 encoded to enable restoring ruby data structures.
@@ -1,5 +1,7 @@
1
1
  require 'couchrest'
2
2
  require 'couchrest_model'
3
+ # ensure compatibility with couchrest_model
4
+ gem 'actionpack', '~> 3.0'
3
5
  require 'action_dispatch'
4
6
 
5
7
  # CouchDB session storage for Rails.
@@ -52,7 +54,12 @@ class CouchRestSessionStore < ActionDispatch::Session::AbstractStore
52
54
  def get_session(env, sid)
53
55
  if sid
54
56
  doc = secure_get(sid)
55
- session = self.class.unmarshal(doc["data"])
57
+ if doc["not_marshalled"]
58
+ session = doc.to_hash
59
+ session.delete("not_marshalled")
60
+ else
61
+ session = self.class.unmarshal(doc["data"])
62
+ end
56
63
  [sid, session]
57
64
  else
58
65
  [generate_sid, {}]
@@ -63,7 +70,7 @@ class CouchRestSessionStore < ActionDispatch::Session::AbstractStore
63
70
  end
64
71
 
65
72
  def set_session(env, sid, session, options)
66
- doc = build_or_update_doc(sid, self.class.marshal(session))
73
+ doc = build_or_update_doc(sid, session, options[:marshal_data])
67
74
  database.save_doc(doc)
68
75
  return sid
69
76
  end
@@ -71,17 +78,28 @@ class CouchRestSessionStore < ActionDispatch::Session::AbstractStore
71
78
  def destroy_session(env, sid, options)
72
79
  doc = secure_get(sid)
73
80
  database.delete_doc(doc)
74
- options[:drop] ? nil : generate_sid
81
+ generate_sid unless options[:drop]
75
82
  rescue RestClient::ResourceNotFound
76
83
  # already destroyed - we're done.
84
+ generate_sid unless options[:drop]
77
85
  end
78
86
 
79
- def build_or_update_doc(sid, data)
87
+ def build_or_update_doc(sid, session, marshal_data)
88
+ marshal_data = true if marshal_data.nil?
80
89
  doc = secure_get(sid)
81
- doc["data"] = data
90
+ doc.clear.merge! data_for_doc(session, marshal_data)
82
91
  return doc
83
92
  rescue RestClient::ResourceNotFound
84
- return CouchRest::Document.new "_id" => sid, "data" => data
93
+ data = data_for_doc(session, marshal_data).merge({"_id" => sid})
94
+ return CouchRest::Document.new(data)
95
+ end
96
+
97
+ def data_for_doc(session, marshal_data)
98
+ if marshal_data
99
+ { "data" => self.class.marshal(session) }
100
+ else
101
+ session.merge({"not_marshalled" => true})
102
+ end
85
103
  end
86
104
 
87
105
  # prevent access to design docs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchrest_session_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchrest
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 1.8.24
92
+ rubygems_version: 1.8.25
93
93
  signing_key:
94
94
  specification_version: 3
95
95
  summary: A Rails Session Store based on CouchRest Model