couchrest_session_store 0.0.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ # CouchRest Session Store #
2
+
3
+ A simple session store based on CouchRest Model - nothing more.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,65 @@
1
+ require 'couchrest'
2
+ require 'couchrest_model'
3
+
4
+ # CouchDB session storage for Rails.
5
+ #
6
+ # It will automatically pick up the config/couch.yml file for CouchRest Model
7
+ #
8
+ # Options:
9
+ # :database => database to use combined with config prefix and suffix
10
+ #
11
+ class CouchRestSessionStore < ActionDispatch::Session::AbstractStore
12
+
13
+ include CouchRest::Model::Configuration
14
+ include CouchRest::Model::Connection
15
+
16
+ class << self
17
+ def marshal(data)
18
+ ::Base64.encode64(Marshal.dump(data)) if data
19
+ end
20
+
21
+ def unmarshal(data)
22
+ Marshal.load(::Base64.decode64(data)) if data
23
+ end
24
+
25
+ end
26
+
27
+ def initialize(app, options = {})
28
+ super
29
+ self.class.use_database options[:database] || "sessions"
30
+ end
31
+
32
+ # just fetch from the config
33
+ def self.database
34
+ @database ||= prepare_database
35
+ end
36
+
37
+ def database
38
+ self.class.database
39
+ end
40
+
41
+ private
42
+
43
+ def get_session(env, sid)
44
+ debugger
45
+ if sid
46
+ doc = database.get(sid)
47
+ session = self.class.unmarshal(doc["data"])
48
+ else
49
+ sid = generate_sid
50
+ session = {}
51
+ doc = CouchRest::Document.new "_id" => sid,
52
+ "data" => self.class.marshal(session)
53
+ database.save_doc(doc)
54
+ end
55
+ return [sid, session]
56
+ end
57
+
58
+ def set_session(env, sid, session, options)
59
+ doc = database.get(sid)
60
+ doc["data"] = self.class.marshal(session)
61
+ database.save_doc(doc)
62
+ return sid
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchrest_session_store
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Azul
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: couchrest
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: couchrest_model
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: A Rails Session Store based on CouchRest Model
49
+ email:
50
+ - azul@leap.se
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - README.md
59
+ - Rakefile
60
+ - lib/couchrest_session_store.rb
61
+ homepage: http://github.com/azul/couchrest_session_store
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.15
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A Rails Session Store based on CouchRest Model
94
+ test_files: []
95
+