Skip to content

Commit

Permalink
rails4: fix activerecord all_models
Browse files Browse the repository at this point in the history
fixes a circular dependency error trying to load
 AccountAuthorizationConfig::CAS

refs #CNVS-21596

Change-Id: I65f92e2cc09228f19363b1964e063a2a5fcde037
Reviewed-on: https://gerrit.instructure.com/57645
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
  • Loading branch information
maneframe committed Jul 6, 2015
1 parent 95ff5d5 commit 1b98577
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions config/initializers/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def feed_code

def self.all_models
return @all_models if @all_models.present?
@all_models = (ActiveRecord::Base.send(:subclasses) +
ActiveRecord::Base.models_from_files +
@all_models = (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 @@ -63,19 +62,14 @@ def self.all_models
end

def self.models_from_files
@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
}
@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
end

def self.maximum_text_length
Expand Down

0 comments on commit 1b98577

Please sign in to comment.