Skip to content

Commit 512fade

Browse files
committed
Initial extract from rails/rails@0cda0b3
0 parents  commit 512fade

File tree

11 files changed

+668
-0
lines changed

11 files changed

+668
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: ruby
2+
rvm:
3+
- 1.9.3

Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source :rubygems
2+
3+
gemspec
4+
5+
if ENV['RAILS']
6+
gem 'activerecord', path: ENV['RAILS']
7+
gem 'actionpack', path: ENV['RAILS']
8+
else
9+
gem 'activerecord', github: 'rails/rails'
10+
gem 'actionpack', github: 'rails/rails'
11+
end
12+
13+
gem 'journey', github: 'rails/journey'
14+
gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2012 David Heinemeier Hansson
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Active Record Session Store
2+
===========================
3+
4+
A session store backed by an Active Record class. A default class is
5+
provided, but any object duck-typing to an Active Record Session class
6+
with text `session_id` and `data` attributes is sufficient.
7+
8+
The default assumes a `sessions` tables with columns:
9+
10+
* `id` (numeric primary key),
11+
* `session_id` (string, usually varchar; maximum length is 255), and
12+
* `data` (text or longtext; careful if your session data exceeds 65KB).
13+
14+
The `session_id` column should always be indexed for speedy lookups.
15+
Session data is marshaled to the `data` column in Base64 format.
16+
If the data you write is larger than the column's size limit,
17+
ActionController::SessionOverflowError will be raised.
18+
19+
You may configure the table name, primary key, and data column.
20+
For example, at the end of `config/application.rb`:
21+
22+
ActiveRecord::SessionStore::Session.table_name = 'legacy_session_table'
23+
ActiveRecord::SessionStore::Session.primary_key = 'session_id'
24+
ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
25+
26+
Note that setting the primary key to the `session_id` frees you from
27+
having a separate `id` column if you don't want it. However, you must
28+
set `session.model.id = session.session_id` by hand! A before filter
29+
on ApplicationController is a good place.
30+
31+
Since the default class is a simple Active Record, you get timestamps
32+
for free if you add `created_at` and `updated_at` datetime columns to
33+
the `sessions` table, making periodic session expiration a snap.
34+
35+
You may provide your own session class implementation, whether a
36+
feature-packed Active Record or a bare-metal high-performance SQL
37+
store, by setting
38+
39+
ActiveRecord::SessionStore.session_class = MySessionClass
40+
41+
You must implement these methods:
42+
43+
* `self.find_by_session_id(session_id)`
44+
* `initialize(hash_of_session_id_and_data, options_hash = {})`
45+
* `attr_reader :session_id`
46+
* `attr_accessor :data`
47+
* `save`
48+
* `destroy`
49+
50+
The example SqlBypass class is a generic SQL session store. You may
51+
use it as a basis for high-performance database-specific stores.

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env rake
2+
require "bundler/gem_tasks"
3+
require 'rake/testtask'
4+
5+
Rake::TestTask.new do |t|
6+
t.libs = ["test"]
7+
t.pattern = "test/**/*_test.rb"
8+
t.ruby_opts = ['-w']
9+
end
10+
11+
task :default => :test

activerecord-session_store.gemspec

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Gem::Specification.new do |s|
2+
s.platform = Gem::Platform::RUBY
3+
s.name = 'activerecord-session_store'
4+
s.version = '0.0.1'
5+
s.summary = 'An Action Dispatch session store backed by an Active Record class.'
6+
7+
s.required_ruby_version = '>= 1.9.3'
8+
s.license = 'MIT'
9+
10+
s.author = 'David Heinemeier Hansson'
11+
s.email = '[email protected]'
12+
s.homepage = 'http://www.rubyonrails.org'
13+
14+
s.files = Dir['CHANGELOG.md', 'MIT-LICENSE', 'README.rdoc', 'lib/**/*']
15+
s.require_path = 'lib'
16+
17+
s.extra_rdoc_files = %w( README.rdoc )
18+
s.rdoc_options.concat ['--main', 'README.rdoc']
19+
20+
s.add_dependency('activerecord', '~> 4.0.0.beta')
21+
s.add_dependency('actionpack', '~> 4.0.0.beta')
22+
23+
s.add_development_dependency('sqlite3')
24+
end

0 commit comments

Comments
 (0)