Created
May 14, 2015 21:39
-
-
Save willcosgrove/e9d5c292554cd3a169b0 to your computer and use it in GitHub Desktop.
The ClientID concern is for facilitating a passthrough of client IDs, useful for reconciling created records with their non-ID'd client counterpart.
This file contains 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 ClientID | |
extend ActiveSupport::Concern | |
included do | |
attr_writer :cid | |
after_commit :_save_cid, on: :create, if: -> { @cid.present? } | |
end | |
def cid | |
Thread.current[_cid_key] | |
end | |
private | |
def _save_cid | |
Thread.current[_cid_key] = @cid | |
end | |
def _cid_key | |
"cid:#{self.class.to_s.tableize}:#{id}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment