Skip to content

Commit

Permalink
Revert "don't cache AbstractModel instances, only model names, this e…
Browse files Browse the repository at this point in the history
…nsures classes are refreshed in development mode"

This reverts commit a904d96.
  • Loading branch information
ryanb authored and sferik committed Feb 26, 2011
1 parent 44480ff commit ef5f625
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/rails_admin/abstract_model.rb
Expand Up @@ -4,11 +4,11 @@
module RailsAdmin
class AbstractModel

@model_names = []
@models = []

# Returns all models for a given Rails app
def self.all
if @model_names.empty?
if @models.empty?
excluded_models = RailsAdmin::Config.excluded_models.map(&:to_s)
excluded_models << ['History']

Expand All @@ -20,13 +20,26 @@ def self.all
end
possible_models = Module.constants | class_names
#Rails.logger.info "possible_models: #{possible_models.inspect}"
models = (possible_models - excluded_models).map { |name| lookup(name, false) }
add_models(possible_models, excluded_models)

#Rails.logger.info "final models: #{models.compact.inspect}"
@model_names = models.compact.map(&:to_s).sort
#Rails.logger.info "final models: #{@models.map(&:model).inspect}"
@models.sort!{|x, y| x.model.to_s <=> y.model.to_s}
end

@model_names.map { |name| new(name.constantize) }
@models
end

def self.add_models(possible_models=[], excluded_models=[])
possible_models.each do |possible_model_name|
next if excluded_models.include?(possible_model_name)
#Rails.logger.info "possible_model_name: #{possible_model_name.inspect}"
add_model(possible_model_name)
end
end

def self.add_model(model_name)
model = lookup(model_name,false)
@models << new(model) if model
end

# Given a string +model_name+, finds the corresponding model class
Expand Down

0 comments on commit ef5f625

Please sign in to comment.