Skip to content

Commit

Permalink
Revert "rails4: fix activerecord all_models"
Browse files Browse the repository at this point in the history
This reverts commit 1b98577.

Change-Id: I1dc7414c1bc062ac7198626197b3540f5e2ad71a
Reviewed-on: https://gerrit.instructure.com/60447
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
Tested-by: Rob Orton <rob@instructure.com>
  • Loading branch information
roor0 committed Aug 10, 2015
1 parent 81dba3b commit 477e40b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions config/initializers/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def feed_code

def self.all_models
return @all_models if @all_models.present?
@all_models = (ActiveRecord::Base.models_from_files +
@all_models = (ActiveRecord::Base.send(:subclasses) +
ActiveRecord::Base.models_from_files +
[Version]).compact.uniq.reject { |model|
!(model.superclass == ActiveRecord::Base || model.superclass.abstract_class?) ||
(model.respond_to?(:tableless?) && model.tableless?) ||
Expand All @@ -62,14 +63,19 @@ def self.all_models
end

def self.models_from_files
@from_files ||= begin
Dir[
"#{Rails.root}/app/models/**/*.rb",
"#{Rails.root}/vendor/plugins/*/app/models/**/*.rb",
"#{Rails.root}/gems/plugins/*/app/models/**/*.rb",
].sort.each { |file| ActiveSupport::Dependencies.require_or_load(file) }
ActiveRecord::Base.descendants
end
@from_files ||= Dir[
"#{Rails.root}/app/models/**/*.rb",
"#{Rails.root}/vendor/plugins/*/app/models/**/*.rb",
"#{Rails.root}/gems/plugins/*/app/models/**/*.rb",
].sort.collect { |file|
model = begin
file.sub(%r{.*/app/models/(.*)\.rb$}, '\1').camelize.constantize
rescue NameError, LoadError
next
end
next unless model < ActiveRecord::Base
model
}
end

def self.maximum_text_length
Expand Down

0 comments on commit 477e40b

Please sign in to comment.