lib/authlogic/session/session.rb in authlogic-4.1.1 vs lib/authlogic/session/session.rb in authlogic-4.2.0

- old
+ new

@@ -28,50 +28,50 @@ # Instance methods for the session feature. module InstanceMethods private - # Tries to validate the session from information in the session - def persist_by_session - persistence_token, record_id = session_credentials - if !persistence_token.nil? - record = persist_by_session_search(persistence_token, record_id) - if record && record.persistence_token == persistence_token - self.unauthorized_record = record - end - valid? - else - false + # Tries to validate the session from information in the session + def persist_by_session + persistence_token, record_id = session_credentials + if !persistence_token.nil? + record = persist_by_session_search(persistence_token, record_id) + if record && record.persistence_token == persistence_token + self.unauthorized_record = record end + valid? + else + false end + end - # Allow finding by persistence token, because when records are created - # the session is maintained in a before_save, when there is no id. - # This is done for performance reasons and to save on queries. - def persist_by_session_search(persistence_token, record_id) - if record_id.nil? - search_for_record("find_by_persistence_token", persistence_token.to_s) - else - search_for_record("find_by_#{klass.primary_key}", record_id.to_s) - end + # Allow finding by persistence token, because when records are created + # the session is maintained in a before_save, when there is no id. + # This is done for performance reasons and to save on queries. + def persist_by_session_search(persistence_token, record_id) + if record_id.nil? + search_for_record("find_by_persistence_token", persistence_token.to_s) + else + search_for_record("find_by_#{klass.primary_key}", record_id.to_s) end + end - def session_credentials - [ - controller.session[session_key], - controller.session["#{session_key}_#{klass.primary_key}"] - ].collect { |i| i.nil? ? i : i.to_s }.compact - end + def session_credentials + [ + controller.session[session_key], + controller.session["#{session_key}_#{klass.primary_key}"] + ].collect { |i| i.nil? ? i : i.to_s }.compact + end - def session_key - build_key(self.class.session_key) - end + def session_key + build_key(self.class.session_key) + end - def update_session - controller.session[session_key] = record && record.persistence_token - compound_key = "#{session_key}_#{klass.primary_key}" - controller.session[compound_key] = record && record.send(record.class.primary_key) - end + def update_session + controller.session[session_key] = record && record.persistence_token + compound_key = "#{session_key}_#{klass.primary_key}" + controller.session[compound_key] = record && record.send(record.class.primary_key) + end end end end end