module ActiveRecord
  class Base
    class << self
      def caches_constants(additional_options = {})
        options = {:key => :name, :limit => 64}.merge(additional_options)
        find(:all).each do |model| 
          const = Viget::Format.to_const(model.send(options[:key].to_sym))
          const = const[0, options[:limit]] unless const.blank?
          set_constant = !const.blank? && !const_defined?(const)
          const_set(const, model) if set_constant
        end
      end
    end
  end
end
module ActiveRecord
  class Base
    class << self
      def caches_constants(additional_options = {})
        options = {:key => :name, :limit => 64}.merge(additional_options)
        find(:all).each do |model| 
          const = Viget::Format.to_const(model.send(options[:key].to_sym))
          unless const.blank?
            const = const[0, options[:limit]]
            const_set(const, model) if !const.blank? && !const_defined?(const)
          end
        end
      end
    end
  end
end
Refactor code per Ben's suggestions
Refactor code per Ben's suggestions

git-svn-id: 61896eb63f1561c389be937852d9629e8857f2e4@134 e959a6d6-1924-0410-92b3-a6fa492f4c66
