Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Adds support for datamapper session stores
Browse files Browse the repository at this point in the history
Usage:

Replace the content of

  * config/initializers/session_store.rb

with the following:

  require 'dm-rails/session_store'
  Rails.application.config.session_store(
    Rails::DataMapper::SessionStore
  }

[#1278 state:resolved]
  • Loading branch information
snusnu committed Jun 3, 2010
1 parent 6922796 commit 2f51741
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/dm-rails/railties/database.rake
Expand Up @@ -110,14 +110,16 @@ namespace :db do
task :create => :environment do
require 'dm-rails/session_store'
Rails::DataMapper::SessionStore::Session.auto_migrate!
::DataMapper.logger.info "Created '#{Rails::DataMapper.configurations[Rails.env]['database']}.sessions'"
database = Rails::DataMapper.configuration.repositories[Rails.env]['database']
::DataMapper.logger.info "Created '#{database}.sessions'"
end

desc "Clear the sessions table for DataMapperStore"
task :clear => :environment do
require 'dm-rails/session_store'
Rails::DataMapper::SessionStore::Session.destroy!
::DataMapper.logger.info "Deleted entries from '#{Rails::DataMapper.configurations[Rails.env]['database']}.sessions'"
database = Rails::DataMapper.configuration.repositories[Rails.env]['database']
::DataMapper.logger.info "Deleted entries from '#{database}.sessions'"
end
end

Expand Down
9 changes: 7 additions & 2 deletions lib/dm-rails/session_store.rb
@@ -1,4 +1,5 @@
require 'dm-core'
require 'active_support/core_ext/class/attribute'

# Implements DataMapper-specific session store.

Expand All @@ -13,18 +14,22 @@ class Session

property :id, Serial
property :session_id, String, :required => true, :unique => true
property :data, Object, :required => true, :default => ActiveSupport::Base64.encode64(Marshal.dump({}))
property :data, Object, :required => true
property :updated_at, DateTime, :index => true

def self.name
'session'
end

def data
attribute_get(:data) || {}
end

end

SESSION_RECORD_KEY = 'rack.session.record'.freeze

cattr_accessor :session_class
class_attribute :session_class
self.session_class = Session

private
Expand Down

1 comment on commit 2f51741

@snusnu
Copy link
Member Author

@snusnu snusnu commented on 2f51741 Jun 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously, the '}' in the commit msg needs to be replaced with a ')'

Please sign in to comment.