Last active
August 29, 2015 14:06
-
-
Save EricLondon/72952b77499badad4e29 to your computer and use it in GitHub Desktop.
Rails Model Concern: track which classes have included the Concern
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
require 'active_support/concern' | |
module ChildTrackable | |
extend ActiveSupport::Concern | |
# keep track of what classes have included this concern: | |
module Children | |
extend self | |
@included_in ||= [] | |
def add(klass) | |
@included_in << klass | |
end | |
def included_in | |
@included_in | |
end | |
end | |
included do | |
# track which classes have included this model concern | |
Children.add self | |
end | |
end | |
# access at: | |
ChildTrackable::Children.included_in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment