Last active
April 17, 2016 09:01
-
-
Save yalab/e332fe7e0bf8f17e75cabbe0adf2e3ed to your computer and use it in GitHub Desktop.
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
# config/initializers/active_record_save_scope_names.rb | |
ActiveSupport.on_load(:active_record) do | |
module SaveScopeNames | |
extend ActiveSupport::Concern | |
module ClassMethods | |
attr_reader :scope_names | |
def scope(*args) | |
@scope_names ||= [] | |
@scope_names << :"#{self.name.downcase}##{args.first}" | |
super | |
end | |
def all_scope_names | |
ActiveRecord::Base.subclasses.map(&:scope_names).flatten.compact | |
end | |
end | |
end | |
ActiveRecord::Base.include(SaveScopeNames) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment