Module Engines
In: lib/engines/assets.rb
lib/engines/plugin/list.rb
lib/engines/plugin/loader.rb
lib/engines/plugin/locator.rb
lib/engines/plugin.rb
lib/engines.rb

Parameters

The Engines module has a number of public configuration parameters:

public_directory
The directory into which plugin assets should be mirrored. Defaults to RAILS_ROOT/public/plugin_assets.
schema_info_table
The table to use when storing plugin migration version information. Defaults to plugin_schema_info.

Additionally, there are a few flags which control the behaviour of some of the features the engines plugin adds to Rails:

disable_application_view_loading
A boolean flag determining whether or not views should be loaded from the main app/views directory. Defaults to false; probably only useful when testing your plugin.
disable_application_code_loading
A boolean flag determining whether or not to load controllers/helpers from the main app directory, if corresponding code exists within a plugin. Defaults to false; again, probably only useful when testing your plugin.
disable_code_mixing
A boolean flag indicating whether all plugin copies of a particular controller/helper should be loaded and allowed to override each other, or if the first matching file should be loaded instead. Defaults to false.

Methods

Classes and Modules

Module Engines::Assets
Module Engines::RailsExtensions
Module Engines::Testing
Class Engines::Plugin

Public Class methods

[Source]

    # File lib/engines.rb, line 84
84:     def init
85:       load_extensions
86:       Engines::Assets.initialize_base_public_directory
87:     end

[Source]

    # File lib/engines.rb, line 93
93:     def load_extensions
94:       rails_extensions.each { |name| require "engines/rails_extensions/#{name}" }
95:       # load the testing extensions, if we are in the test environment.
96:       require "engines/testing" if RAILS_ENV == "test"
97:     end

[Source]

    # File lib/engines.rb, line 89
89:     def logger
90:       RAILS_DEFAULT_LOGGER
91:     end

A general purpose method to mirror a directory (source) into a destination directory, including all files and subdirectories. Files will not be mirrored if they are identical already (checked via FileUtils#identical?).

[Source]

     # File lib/engines.rb, line 138
138:     def mirror_files_from(source, destination)
139:       return unless File.directory?(source)
140:       
141:       # TODO: use Rake::FileList#pathmap?    
142:       source_files = Dir[source + "/**/*"]
143:       source_dirs = source_files.select { |d| File.directory?(d) }
144:       source_files -= source_dirs
145:       
146:       unless source_files.empty?
147:         base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
148:         FileUtils.mkdir_p(base_target_dir)
149:       end
150:       
151:       source_dirs.each do |dir|
152:         # strip down these paths so we have simple, relative paths we can
153:         # add to the destination
154:         target_dir = File.join(destination, dir.gsub(source, ''))
155:         begin        
156:           FileUtils.mkdir_p(target_dir)
157:         rescue Exception => e
158:           raise "Could not create directory #{target_dir}: \n" + e
159:         end
160:       end
161:       
162:       source_files.each do |file|
163:         begin
164:           target = File.join(destination, file.gsub(source, ''))
165:           unless File.exist?(target) && FileUtils.identical?(file, target)
166:             FileUtils.cp(file, target)
167:           end 
168:         rescue Exception => e
169:           raise "Could not copy #{file} to #{target}: \n" + e 
170:         end
171:       end  
172:     end

The engines plugin will, by default, mix code from controllers and helpers, allowing application code to override specific methods in the corresponding controller or helper classes and modules. However, if other file types should also be mixed like this, they can be added by calling this method. For example, if you want to include "things" within your plugin and override them from your applications, you should use the following layout:

  app/
   +-- things/
   |       +-- one_thing.rb
   |       +-- another_thing.rb
  ...
  vendor/
      +-- plugins/
               +-- my_plugin/
                          +-- app/
                               +-- things/
                                       +-- one_thing.rb
                                       +-- another_thing.rb

The important point here is that your "things" are named <whatever>_thing.rb, and that they are placed within plugin/app/things (the pluralized form of ‘thing’).

It‘s important to note that you‘ll also want to ensure that the "things" are on your load path in your plugin‘s init.rb:

  Rails.plugins[:my_plugin].code_paths << "app/things"

[Source]

     # File lib/engines.rb, line 131
131:     def mix_code_from(*types)
132:       self.code_mixing_file_types += types.map { |x| x.to_s.singularize }
133:     end

[Source]

     # File lib/engines.rb, line 99
 99:     def select_existing_paths(paths)
100:       paths.select { |path| File.directory?(path) }
101:     end

[Validate]