Last active
November 27, 2018 18:30
-
-
Save ritikesh/1c0d1af520cb82caa93c40008f45a019 to your computer and use it in GitHub Desktop.
Current pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActsAsCurrent | |
extend ActiveSupport::Concern | |
included do | |
self._current_human_name = self.name.underscore.to_sym | |
end | |
def make_current | |
Thread.current[self.class._current_human_name] = self | |
end | |
module ClassMethods | |
attr_reader :_current_human_name | |
def current | |
Thread.current[_current_human_name] | |
end | |
def reset_current | |
Thread.current[_current_human_name] = nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment