12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/dragonfly_extensions/monkey_patches.rb', line 12
def self.all_polymorphic_types(name)
@poly_hash ||= {}.tap do |hash|
Dir.glob(File.join(RAILS_ROOT, "app", "models", "**", "*.rb")).each do |file|
klass = (File.basename(file, ".rb").camelize.constantize rescue nil)
next if klass.nil? or !klass.ancestors.include?(ActiveRecord::Base)
klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection|
(hash[reflection.options[:as]] ||= []) << klass
end
end
end
@poly_hash[name.to_sym]
end
|