Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3193

Show
Ignore:
Timestamp:
11/28/05 20:39:26 (3 years ago)
Author:
bitsweat
Message:

Handle mutual dependencies with .rb suffix.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/dependencies.rb

    r3190 r3193  
    2828 
    2929  def depend_on(file_name, swallow_load_errors = false) 
    30     unless loaded.include?(file_name) 
    31       begin 
    32         require_or_load(file_name) 
    33       rescue LoadError 
    34         raise unless swallow_load_errors 
    35       end 
    36     end 
     30    require_or_load(file_name) 
     31  rescue LoadError 
     32    raise unless swallow_load_errors 
    3733  end 
    3834 
     
    4642 
    4743  def require_or_load(file_name) 
     44    file_name = $1 if file_name =~ /^(.*)\.rb$/ 
     45    return if loaded.include?(file_name) 
     46 
     47    # Record that we've seen this file *before* loading it to avoid an 
     48    # infinite loop with mutual dependencies. 
     49    loaded << file_name 
     50 
    4851    if load? 
    49       # Append .rb if we have a bare file name. 
    50       load_file_name = (file_name =~ /\.rb$/ ? file_name : "#{file_name}.rb") 
    51  
    52       # Record that we've seen this file *before* loading it to avoid an 
    53       # infinite loop with mutual dependencies. 
    54       loaded << file_name 
    55  
    5652      begin 
    5753        # Enable warnings iff this file has not been loaded before and 
    5854        # warnings_on_first_load is set. 
    5955        if !warnings_on_first_load or history.include?(file_name) 
    60           load load_file_name 
     56          load "#{file_name}.rb" 
    6157        else 
    62           enable_warnings { load load_file_name
     58          enable_warnings { load "#{file_name}.rb"
    6359        end 
    6460      rescue 
  • trunk/activesupport/test/dependencies/mutual_one.rb

    r3181 r3193  
    11$mutual_dependencies_count += 1 
    22require_dependency 'mutual_two' 
     3require_dependency 'mutual_two.rb' 
     4require_dependency 'mutual_two' 
  • trunk/activesupport/test/dependencies/mutual_two.rb

    r3181 r3193  
    11$mutual_dependencies_count += 1 
     2require_dependency 'mutual_one.rb' 
    23require_dependency 'mutual_one' 
     4require_dependency 'mutual_one.rb'