Class: Edgarj::Sssn
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Edgarj::Sssn
- Defined in:
- app/models/edgarj/sssn.rb
Overview
Edgarj specific session
ActiveRecord::SessionStore::Session and Sssn are merged into Sssn because:
-
I could not find the way to build/prepare session for test;-(
-
It was verbose to Sync Sssn and Session.
See ActiveRecord::SessionStore how to do that.
Instance Attribute Summary collapse
-
#data ⇒ Object
Lazy-unmarshal session state.
Class Method Summary collapse
- .data_column_size_limit ⇒ Object
-
.delete_stale_sessions(dry_run = true) ⇒ Object
delete stale sessions no longer active than SESSION_TIME_OUT minutes ago.
- .find_by_session_id(session_id) ⇒ Object
- .marshal(data) ⇒ Object
- .unmarshal(data) ⇒ Object
Instance Method Summary collapse
- #before_destroy ⇒ Object
-
#loaded? ⇒ Boolean
Has the session been loaded yet?.
- #name ⇒ Object
Instance Attribute Details
#data ⇒ Object
Lazy-unmarshal session state.
52 53 54 |
# File 'app/models/edgarj/sssn.rb', line 52 def data @data ||= self.class.unmarshal(read_attribute('data')) || {} end |
Class Method Details
.data_column_size_limit ⇒ Object
27 28 29 |
# File 'app/models/edgarj/sssn.rb', line 27 def data_column_size_limit @data_column_size_limit ||= columns_hash['data'].limit end |
.delete_stale_sessions(dry_run = true) ⇒ Object
delete stale sessions no longer active than SESSION_TIME_OUT minutes ago
INPUTS
- dry_run
-
dry-run mode (default = true)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/edgarj/sssn.rb', line 90 def self.delete_stale_sessions(dry_run=true) self.transaction do for s in Sssn.all( :conditions=>['updated_at<?', Edgarj::BaseConfig::SESSION_TIME_OUT.minutes.ago.utc]) do begin session_id = s.session_id s.destroy logger.info("deleting session(#{session_id})") rescue ActiveRecord::RecordNotFound logger.warn("session not found(#{session_id})") end end raise ActiveRecord::Rollback if dry_run end end |
.find_by_session_id(session_id) ⇒ Object
31 32 33 |
# File 'app/models/edgarj/sssn.rb', line 31 def find_by_session_id(session_id) where(session_id: session_id).first end |
.marshal(data) ⇒ Object
35 36 37 |
# File 'app/models/edgarj/sssn.rb', line 35 def marshal(data) Base64.encode64(Marshal.dump(data)) if data end |
.unmarshal(data) ⇒ Object
39 40 41 |
# File 'app/models/edgarj/sssn.rb', line 39 def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end |
Instance Method Details
#before_destroy ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'app/models/edgarj/sssn.rb', line 110 def before_destroy if Edgarj::Login::ENABLE_LOGGING a = ActionEntry.new a.user = self.user a.action = Action::Login.new(:kind=>Action::Login::Kind::LOGOUT) a.save! end true end |
#loaded? ⇒ Boolean
Has the session been loaded yet?
59 60 61 |
# File 'app/models/edgarj/sssn.rb', line 59 def loaded? !!@data end |
#name ⇒ Object
106 107 108 |
# File 'app/models/edgarj/sssn.rb', line 106 def name user.name + ' session' end |