Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

autoload + config.threadsafe! broken?

#5241

How to reproduce:
0. Add lib/ to autoloaded paths
1. Have class Foo in lib/foo.rb
2. Have config.threadsafe! option on
3. Launch rails console production
4. Type Foo

Expected behaviour: autoloaded lib/foo.rb
Existing behaviour: missing constant exception

Quick note: for nested constants like Foo::Bar it does load foo/bar.rb file but not for ::Foo constant

Reported by mark · July 29th, 2010 @ 04:37 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. mark
    mark

    If anyone is interested, here's the solution (in initializer) I use for now:

    Dir.chdir "#{Rails.root}/lib/" do

    Dir["**/*.rb"].each do |lib|
      basename = lib.match(/(.*)\.rb$/)[1].classify
      parts = basename.split("::")
      if parts.size > 1
        eval <<-EVAL
          module ::#{parts[0..-2].join("::")}
            autoload :#{parts[-1]}, "#{File.expand_path(lib)}"
          end
        EVAL
      else
        autoload parts[0].classify.to_sym, File.expand_path(lib)
      end
    end
    

    end

    Ideas, anyone?

    Checked this vs ruby 1.9.2-head.

    July 30th, 2010 @ 07:12 PM

  2. Jacek Becela
    Jacek Becela

    Having the same problem on 1.8.7 and regular models located in app/models.

    August 23rd, 2010 @ 04:48 PM

  3. Jacek Becela
    Jacek Becela

    Probably not a bug, following is the documentation for #threadsafe!

      # Enable threaded mode. Allows concurrent requests to controller actions and
      # multiple database connections. Also disables automatic dependency loading
      # after boot, and disables reloading code on every request, as these are
      # fundamentally incompatible with thread safety.
    

    August 23rd, 2010 @ 04:52 PM

  4. mark
    mark

    Seems like that doc isn't for long. Probably the issue could be documented and closed.
    The temporary solution I use still seems to work, though.

    August 23rd, 2010 @ 05:33 PM

  5. mark
    mark

    isn't for long "hasn't been there for a long time" disambiguation fix

    August 23rd, 2010 @ 05:35 PM

  6. mark
    mark

    isn't for long

    "hasn't been there for a long time" - disambiguation fix. Sry for flood, having no edit option hurts.

    August 23rd, 2010 @ 05:36 PM

  7. Rohit Arondekar
    Rohit Arondekar
    • Importance changed from to Low

    Mark, since documentation for #threadsafe! already mentions this, can this ticket be closed?

    August 25th, 2010 @ 03:03 AM

  8. mark
    mark

    Yeah, seems it won't fix.

    August 25th, 2010 @ 07:09 AM

  9. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid

    August 25th, 2010 @ 11:31 AM