Skip to content

Commit

Permalink
Merge pull request binarylogic#729 from binarylogic/thread_safety_726
Browse files Browse the repository at this point in the history
[Fix binarylogic#726] Thread safety: Session::Base.klass_name
  • Loading branch information
jaredbeck committed Sep 10, 2020
2 parents 08113df + 606f774 commit 32942b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Added
* None
* Fixed
* None
* [#726](https://github.com/binarylogic/authlogic/issues/726) - Thread
safety in `Authlogic::Session::Base.klass_name`

## 6.2.0 (2020-09-03)

Expand Down
16 changes: 12 additions & 4 deletions lib/authlogic/session/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,15 +776,23 @@ def i18n_scope
# example, the UserSession class will authenticate with the User class
# unless you specify otherwise in your configuration. See
# authenticate_with for information on how to change this value.
#
# @api public
def klass
@klass ||= klass_name ? klass_name.constantize : nil
end

# The string of the model name class guessed from the actual session class name.
# The model name, guessed from the session class name, e.g. "User",
# from "UserSession".
#
# TODO: This method can return nil. We should explore this. It seems
# likely to cause a NoMethodError later, so perhaps we should raise an
# error instead.
#
# @api private
def klass_name
return @klass_name if defined?(@klass_name)
@klass_name = name.scan(/(.*)Session/)[0]
@klass_name = klass_name ? klass_name[0] : nil
return @klass_name if instance_variable_defined?(:@klass_name)
@klass_name = name.scan(/(.*)Session/)[0]&.first
end

# The name of the method you want Authlogic to create for storing the
Expand Down

0 comments on commit 32942b0

Please sign in to comment.