Class: ActiveRecord::SessionStore::SqlBypass

### Home Classes Methods

### In Files

- lib/active_record/session_store.rb

### Parent

Object

### Methods

- ::connection
- ::data_column
- ::data_column_name
- ::find_by_session_id
- ::new
- ::session_id_column
- ::table_name
- #data
- #destroy
- #loaded?
- #save

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::ActiveRecordError
- ActiveRecord::AdapterNotFound
- ActiveRecord::AdapterNotSpecified
- ActiveRecord::Aggregations
- ActiveRecord::Aggregations::ClassMethods
- ActiveRecord::AssociationPreload
- ActiveRecord::AssociationPreload::ClassMethods
- ActiveRecord::AssociationTypeMismatch
- ActiveRecord::Associations
- ActiveRecord::Associations::ClassMethods
- ActiveRecord::Associations::HasOneThroughAssociation
- ActiveRecord::Associations::ThroughAssociationScope
- ActiveRecord::AttributeAssignmentError
- ActiveRecord::AttributeMethods
- ActiveRecord::AttributeMethods::BeforeTypeCast
- ActiveRecord::AttributeMethods::ClassMethods
- ActiveRecord::AttributeMethods::Dirty
- ActiveRecord::AttributeMethods::PrimaryKey
- ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods
- ActiveRecord::AttributeMethods::Query
- ActiveRecord::AttributeMethods::Read
- ActiveRecord::AttributeMethods::Read::ClassMethods
- ActiveRecord::AttributeMethods::TimeZoneConversion
- ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods
- ActiveRecord::AttributeMethods::Write
- ActiveRecord::AttributeMethods::Write::ClassMethods
- ActiveRecord::AutosaveAssociation
- ActiveRecord::AutosaveAssociation::ClassMethods
- ActiveRecord::Base
- ActiveRecord::Calculations
- ActiveRecord::Callbacks
- ActiveRecord::Callbacks::ClassMethods
- ActiveRecord::ConfigurationError
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::ConnectionAdapters::Column::Format
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- ActiveRecord::ConnectionAdapters::ConnectionManagement
- ActiveRecord::ConnectionAdapters::ConnectionPool
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::SQLiteAdapter
- ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- ActiveRecord::ConnectionAdapters::SchemaStatements
- ActiveRecord::ConnectionAdapters::Table
- ActiveRecord::ConnectionAdapters::TableDefinition
- ActiveRecord::ConnectionNotEstablished
- ActiveRecord::ConnectionTimeoutError
- ActiveRecord::CounterCache
- ActiveRecord::DangerousAttributeError
- ActiveRecord::DynamicFinderMatch
- ActiveRecord::DynamicScopeMatch
- ActiveRecord::FinderMethods
- ActiveRecord::Generators
- ActiveRecord::Generators::Migration
- ActiveRecord::Generators::MigrationGenerator
- ActiveRecord::Generators::ModelGenerator
- ActiveRecord::Generators::ObserverGenerator
- ActiveRecord::Generators::SessionMigrationGenerator
- ActiveRecord::InvalidForeignKey
- ActiveRecord::IrreversibleMigration
- ActiveRecord::Locking
- ActiveRecord::Locking::Optimistic
- ActiveRecord::Locking::Optimistic::ClassMethods
- ActiveRecord::Locking::Pessimistic
- ActiveRecord::LogSubscriber
- ActiveRecord::Migration
- ActiveRecord::MigrationProxy
- ActiveRecord::MultiparameterAssignmentErrors
- ActiveRecord::NamedScope
- ActiveRecord::NamedScope::ClassMethods
- ActiveRecord::NestedAttributes
- ActiveRecord::NestedAttributes::ClassMethods
- ActiveRecord::NestedAttributes::TooManyRecords
- ActiveRecord::Observer
- ActiveRecord::Persistence
- ActiveRecord::PredicateBuilder
- ActiveRecord::PreparedStatementInvalid
- ActiveRecord::QueryCache
- ActiveRecord::QueryCache::ClassMethods
- ActiveRecord::QueryMethods
- ActiveRecord::Railtie
- ActiveRecord::Railties
- ActiveRecord::Railties::ControllerRuntime
- ActiveRecord::Railties::ControllerRuntime::ClassMethods
- ActiveRecord::ReadOnlyRecord
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::RecordNotUnique
- ActiveRecord::Reflection
- ActiveRecord::Reflection::ClassMethods
- ActiveRecord::Reflection::MacroReflection
- ActiveRecord::Relation
- ActiveRecord::Rollback
- ActiveRecord::Schema
- ActiveRecord::Serialization
- ActiveRecord::SerializationTypeMismatch
- ActiveRecord::SessionStore
- ActiveRecord::SessionStore::Session
- ActiveRecord::SessionStore::SqlBypass
- ActiveRecord::SpawnMethods
- ActiveRecord::StaleObjectError
- ActiveRecord::StatementInvalid
- ActiveRecord::TestFixtures
- ActiveRecord::TestFixtures::ClassMethods
- ActiveRecord::ThrowResult
- ActiveRecord::Timestamp
- ActiveRecord::Transactions
- ActiveRecord::Transactions::ClassMethods
- ActiveRecord::UnknownAttributeError
- ActiveRecord::Validations
- ActiveRecord::Validations::AssociatedValidator
- ActiveRecord::Validations::ClassMethods
- ActiveRecord::Validations::UniquenessValidator
- ActiveRecord::WrappedDatabaseException
- <
- Fixtures
- FixturesFileNotFound

No matching classes.

# ActiveRecord::SessionStore::SqlBypass

A barebones session store which duck-types with the default session store but bypasses Active Record and issues SQL directly. This is an example session model class meant as a basis for your own classes.

The database connection, table name, and session id and data columns are configurable class attributes. Marshaling and unmarshaling are implemented as class methods that you may override. By default, marshaling data is

    ActiveSupport::Base64.encode64(Marshal.dump(data))

and unmarshaling data is

    Marshal.load(ActiveSupport::Base64.decode64(data))

This marshaling behavior is intended to store the widest range of binary session data in a `text` column. For higher performance, store in a `blob` column instead and forgo the Base64 encoding.

### Attributes

data[W]
new_record[R]
new_record?[R]
session_id[R]

### Public Class Methods

connection click to toggle source

Use the ActiveRecord::Base.connection by default.

    # File lib/active_record/session_store.rb, line 183
    cattr_accessor :connection

data_column click to toggle source

The data field defaults to ‘data’.

    # File lib/active_record/session_store.rb, line 200
    cattr_accessor :data_column

Also aliased as: data_column_name
data_column_name click to toggle source
Alias for: data_column
find_by_session_id(session_id) click to toggle source

Look up a session by id and unmarshal its data if found.

    # File lib/active_record/session_store.rb, line 212
    def find_by_session_id(session_id)
      if record = connection.select_one("SELECT * FROM #{@@table_name} WHERE #{@@session_id_column}=#{connection.quote(session_id)}")
        new(:session_id => session_id, :marshaled_data => record['data'])
      end
    end

new(attributes) click to toggle source

Look for normal and marshaled data, self.find_by_session_id’s way of telling us to postpone unmarshaling until the data is requested. We need to handle a normal data attribute in case of a new record.

    # File lib/active_record/session_store.rb, line 227
    def initialize(attributes)
      @session_id     = attributes[:session_id]
      @data           = attributes[:data]
      @marshaled_data = attributes[:marshaled_data]
      @new_record     = @marshaled_data.nil?
    end

session_id_column click to toggle source

The session id field defaults to ‘session_id’.

    # File lib/active_record/session_store.rb, line 194
    cattr_accessor :session_id_column

table_name click to toggle source

The table name defaults to ‘sessions’.

    # File lib/active_record/session_store.rb, line 188
    cattr_accessor :table_name

### Public Instance Methods

data() click to toggle source

Lazy-unmarshal session state.

    # File lib/active_record/session_store.rb, line 235
    def data
      unless @data
        if @marshaled_data
          @data, @marshaled_data = self.class.unmarshal(@marshaled_data) || {}, nil
        else
          @data = {}
        end
      end
      @data
    end

destroy() click to toggle source

    # File lib/active_record/session_store.rb, line 274
    def destroy
      return if @new_record

      connect = connection
      connect.delete           DELETE FROM #{table_name}          WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id)}, 'Destroy session'
    end

loaded?() click to toggle source

    # File lib/active_record/session_store.rb, line 246
    def loaded?
      @data
    end

save() click to toggle source

    # File lib/active_record/session_store.rb, line 250
    def save
      return false unless loaded?
      marshaled_data = self.class.marshal(data)
      connect        = connection

      if @new_record
        @new_record = false
        connect.update             INSERT INTO #{table_name} (              #{connect.quote_column_name(session_id_column)},              #{connect.quote_column_name(data_column)} )            VALUES (              #{connect.quote(session_id)},              #{connect.quote(marshaled_data)} ), 'Create session'
      else
        connect.update             UPDATE #{table_name}            SET #{connect.quote_column_name(data_column)}=#{connect.quote(marshaled_data)}            WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id)}, 'Update session'
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.