Created
April 4, 2020 07:21
-
-
Save zhum/c64ef311df40af9928a3d8e50f490da8 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
module Comments | |
class ModelsList | |
if Rails.env.production? | |
def self.to_a | |
@@to_a ||= load | |
end | |
def self.to_a_labels | |
@@to_a_labels ||= to_a.map { |m| "#{m}|#{eval(m).model_name.human}"} | |
end | |
else | |
def self.to_a | |
load | |
end | |
def self.to_a_labels | |
to_a.map { |m| "#{m}|#{eval(m).model_name.human}"} | |
end | |
end | |
def self.load | |
res = [] | |
Rails::Engine.subclasses.map do |r| | |
mod_name = eval(r.name.split(/::/).first) | |
res += mod_name.constants.select do |c| | |
cl = eval("#{mod_name}::#{c}") | |
cl.is_a?(Class) && cl < ActiveRecord::Base | |
end.map{ |c| "#{mod_name}::#{c}" } | |
end | |
res += Module.constants.select do |c| | |
cl = eval("#{c}") | |
cl.is_a?(Class) && cl < ActiveRecord::Base | |
end.map(&:to_s) | |
res.sort | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment