Skip to content

Instantly share code, notes, and snippets.

@ritikesh
Last active November 27, 2018 18:30
Show Gist options
  • Save ritikesh/1c0d1af520cb82caa93c40008f45a019 to your computer and use it in GitHub Desktop.
Save ritikesh/1c0d1af520cb82caa93c40008f45a019 to your computer and use it in GitHub Desktop.
Current pattern
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