Module: Oasis::Loader

Defined in:
lib/oasis/loader.rb

Overview

only require this if you need it. This is designed for use as pre-initializer. do not bother setting this within your engine’s init.rb file, its too late by then.

Class Method Summary collapse

Class Method Details

.add_app_load_path_support_for(*names) ⇒ Object

this method defines a series of methods and method chains that can be used to augment the plugin/engines loader to consider more potential load paths within the app/ directory. this should only be necessary if you have code hiding in a top-level directory, beneath vendor/plugins/<your_engine>/app eg: vendor/plugins/<your_engine>/app/cells

this method should be used in the master environment.rb of your rails application.

example:

require ‘oasis/loader’ Oasis::Loader.add_app_load_path_support_for :cells

Rails::Initializer.run do |config|

...

end



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oasis/loader.rb', line 23

def self.add_app_load_path_support_for(*names)
  names.each do |name|
    Rails::Plugin.class_eval <<-EOS
      def has_#{name}_directory?                                     #    def has_cells_directory?
        File.directory?(File.join(directory, 'app', '#{name}'))      #      File.directory?(File.join(directory, 'app', 'cells'))
      end                                                            #    end
                                                                     #    
      def #{name}_path                                               #    def cells_path
        File.join(directory, 'app', '#{name}')                       #      File.join(directory, 'app', 'cells')
      end                                                            #    end
                                                                     #    
      def load_paths_with_#{name}                                    #    def load_paths_with_cells
        paths = load_paths_without_#{name}                           #      paths = load_paths_without_cells
        paths << #{name}_path if has_#{name}_directory?              #      paths << cells_path if has_cells_directory?
        paths                                                        #      paths
      end                                                            #    end
      alias_method :load_paths_without_#{name}, :load_paths
      alias_method :load_paths, :load_paths_with_#{name}
    EOS
  end
end