Module: ActiveSupport::Dependencies

Defined in:
lib/active_support-dependencies_patch.rb

Instance Method Summary collapse

Instance Method Details

#engine_pathsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_support-dependencies_patch.rb', line 7

def engine_paths()
  @engine_paths ||= begin
    begin
      # Rails 3.1 onwards
      Rails::Application::Railties.engines.collect { |engine| engine.config.root.to_s }
    rescue
      begin
        # Rails 3.0
        Rails::Application.railties.engines.collect { |engine| engine.config.root.to_s }
      rescue
        # Rails 2.x
        [] # must be manually registered via ActiveSupport::Dependencies.engine_paths << engine
      end
    end
  end
end

#observe_require(file) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/active_support-dependencies_patch.rb', line 49

def observe_require( file )
  yield
rescue => x
  # STDERR.puts "AS:DP Failed to required #{file} due to an error #{x.inspect}"
  raise x
else
  # STDERR.puts "AS:DP Required #{file}"
end

#require_or_load(file_name, const_path = nil) ⇒ Object

redefine the method



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_support-dependencies_patch.rb', line 28

def require_or_load(file_name, const_path = nil)
  if file_name.starts_with?( "#{Rails.root}/app" ) || file_name.starts_with?( "#{Rails.root}/lib" )
    relative_name = file_name.gsub( Rails.root.to_s, '' )
    engine_paths.each do |path|
      engine_file = File.join( path, relative_name )
      
      # call the original method
      if File.file?( engine_file ) then
        observe_require( "engine file #{engine_file} path #{const_path}" ) {
          require_or_load_without_multiple( engine_file, const_path )
        }
      end
    end
  end
  
  # call the original method
  observe_require( "original file #{file_name} path #{const_path}" ) {
    require_or_load_without_multiple( file_name, const_path )
  }
end

#require_or_load_without_multipleObject

alias new name ‘require_or_load_without_multiple’ to existing method ‘require_or_load’



25
# File 'lib/active_support-dependencies_patch.rb', line 25

alias_method :require_or_load_without_multiple, :require_or_load