Class: ActiveRecord::SessionStore::Session

Inherits:
Base
  • Object
show all
Defined in:
lib/active_record/session_store.rb

Overview

The default Active Record class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, ===, #[], #[]=, abstract_class?, accessible_attributes, all, allow_concurrency, allow_concurrency=, attr_accessible, attr_protected, attr_readonly, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #attributes=, #attributes_before_type_cast, base_class, #becomes, benchmark, #cache_key, class_name, #clone, #colorize_logging, #column_for_attribute, column_methods_hash, column_names, columns, columns_hash, #configurations, connected?, #connection, connection, #connection_handler, connection_pool, content_columns, count_by_sql, create, #decrement, #decrement!, decrement_counter, #default_timezone, delete, #delete, delete_all, descends_from_active_record?, destroy, #destroy, destroy_all, #destroyed?, #eql?, establish_connection, exists?, find, find_by_sql, finder_needs_type_condition?, first, #freeze, #frozen?, full_table_name_prefix, get_primary_key, #has_attribute?, #hash, human_attribute_name, human_name, #id, #id=, #id_before_type_cast, #increment, #increment!, increment_counter, inheritance_column, inherited, #initialize, inspect, #inspect, last, #logger, merge_conditions, mysql_connection, #new_record?, #pluralize_table_names, postgresql_connection, primary_key, #primary_key_prefix_type, protected_attributes, quote_value, #quoted_id, #readonly!, #readonly?, readonly_attributes, #reload, remove_connection, reset_column_information, reset_column_information_and_inheritable_attributes_for_all_subclasses, reset_counters, reset_primary_key, reset_sequence_name, reset_subclasses, reset_table_name, respond_to?, retrieve_connection, sanitize, #save, #save!, #schema_format, self_and_descendants_from_active_record, sequence_name, serialize, serialized_attributes, set_inheritance_column, set_primary_key, set_sequence_name, set_table_name, silence, sqlite3_connection, sqlite_connection, sti_name, table_exists?, table_name, #table_name_prefix, #table_name_suffix, #timestamped_migrations, #to_param, #toggle, #toggle!, update, update_all, #update_attribute, #update_attributes, #update_attributes!, #update_attributes_inside_transaction, #update_attributes_inside_transaction!, update_counters, verification_timeout, verification_timeout=

Constructor Details

This class inherits a constructor from ActiveRecord::Base

Instance Attribute Details

#dataObject

Lazy-unmarshal session state.



109
110
111
# File 'lib/active_record/session_store.rb', line 109

def data
  @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {}
end

Class Method Details

.create_table!Object



74
75
76
77
78
79
80
81
82
# File 'lib/active_record/session_store.rb', line 74

def create_table!
  connection.execute <<-end_sql
    CREATE TABLE #{table_name} (
      id INTEGER PRIMARY KEY,
      #{connection.quote_column_name('session_id')} TEXT UNIQUE,
      #{connection.quote_column_name(@@data_column_name)} TEXT(255)
    )
  end_sql
end

.data_column_size_limitObject



56
57
58
# File 'lib/active_record/session_store.rb', line 56

def data_column_size_limit
  @data_column_size_limit ||= columns_hash[@@data_column_name].limit
end

.drop_table!Object



84
85
86
# File 'lib/active_record/session_store.rb', line 84

def drop_table!
  connection.execute "DROP TABLE #{table_name}"
end

.find_by_session_id(session_id) ⇒ Object

Hook to set up sessid compatibility.



61
62
63
64
# File 'lib/active_record/session_store.rb', line 61

def find_by_session_id(session_id)
  setup_sessid_compatibility!
  find_by_session_id(session_id)
end

.marshal(data) ⇒ Object



66
67
68
# File 'lib/active_record/session_store.rb', line 66

def marshal(data)
  ActiveSupport::Base64.encode64(Marshal.dump(data)) if data
end

.unmarshal(data) ⇒ Object



70
71
72
# File 'lib/active_record/session_store.rb', line 70

def unmarshal(data)
  Marshal.load(ActiveSupport::Base64.decode64(data)) if data
end

Instance Method Details

#data_column_nameObject

:singleton-method: Customizable data column name. Defaults to ‘data’.



49
# File 'lib/active_record/session_store.rb', line 49

cattr_accessor :data_column_name

#loaded?Boolean

Has the session been loaded yet?

Returns:

  • (Boolean)


116
117
118
# File 'lib/active_record/session_store.rb', line 116

def loaded?
  !!@data
end