Sha256: a247013441c7165878ca0021a4f70608f572c7037feba709e0b887e42f808e9b

Contents?: true

Size: 625 Bytes

Versions: 8

Compression:

Stored size: 625 Bytes

Contents

# load all models before each request so relations in datamapper find their classes
MODELS = []
Dir[RAILS_ROOT + "/app/models/**/*.rb"].each do |model|
  model.sub!(/.*models\//, '').sub!(/.rb/, '')
  m = ::Extlib::Inflection.classify(model.to_s)
  MODELS << m
  Object.const_get(m)
end

module ModelLoader
  module Base
    def self.included(base)
      base.prepend_before_filter(ModelLoaderFilter)
    end
  end
  
  class ModelLoaderFilter
    def self.filter(controller)
      MODELS.each do |model|
        Object.const_get(model)
      end
    end
  end
end

::ActionController::Base.send(:include, ModelLoader::Base)

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
datamapper4rails-0.5.2 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.5.1 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.5.0 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.4.0 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.3.2 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.3.1 lib/datamapper4rails/preload_models.rb
datamapper4rails-0.3.0 lib/datamapper4rails/preload_models.rb
datamapper4rail-0.2.0 lib/datamapper4rails/preload_models.rb