Method: Annotate.eager_load

Defined in:
lib/annotate.rb

.eager_load(options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/annotate.rb', line 84

def self.eager_load(options)
  load_requires(options)
  require 'annotate/active_record_patch'

  if defined?(Rails::Application)
    if Rails.version.split('.').first.to_i < 3
      Rails.configuration.eager_load_paths.each do |load_path|
        matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
        Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
          require_dependency file.sub(matcher, '\1')
        end
      end
    else
      klass = Rails::Application.send(:subclasses).first
      klass.eager_load!
    end
  else
    options[:model_dir].each do |dir|
      FileList["#{dir}/**/*.rb"].each do |fname|
        require File.expand_path(fname)
      end
    end
  end
end