views:

92

answers:

1

I am facing an issue where my Rails application is set to cache classes when run in the staging or production environment. While load_paths only contains 'app/models', it appears that the initialization steps recursively caches everything in 'app/models'.

  # Eager load application classes
  def load_application_classes
    if configuration.cache_classes
      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
    end
  end

The problem in this is that we have a sub directory within 'app/models' that contains files with require statements that reference a concurrent JRuby environment. Since Rails knows nothing of this environment our application breaks on load.

As it stands, here are the proposed solutions...unfortunately only #1 is ideal.

1) The simplest solution would be to exclude the culprit sub directory, but have not found anything how to accomplish this.

2) Monkey patch the load_application_classes method to skip the specific sub directory.

3) Move the sub directory out from under 'app/models'. Feels a bit hackish and would require quite a few code changes.

Thoughts?

A: 

Hi,

As a temporary measure you could go with a version of option 2 and override the definition of load_application_classes, replacing it with an empty implementation. That would force you to explicitly require the classes you need but it would give you complete control over what gets loaded and would be a completely transparent solution.

It sounds like your application is sufficiently sophisticated that it's growing beyond the Rails framework. I know that this doesn't directly answer your question so appologies in advance but you may want to consider looking at an alternative Ruby framework like Merb. Rails is great but sooner or later you bump into edge of the framework - sounds like that's where you are now.

We made the switch to Merb last year and haven't regreated it.

Chris

Chris McCauley