Module: Engines
- Defined in:
- vendor/plugins/engines/lib/engines.rb,
vendor/plugins/engines/lib/engines/assets.rb,
vendor/plugins/engines/lib/engines/plugin.rb,
vendor/plugins/engines/lib/engines/plugin/list.rb,
vendor/plugins/engines/lib/engines/plugin/loader.rb,
vendor/plugins/engines/lib/engines/plugin/locator.rb
Overview
The PluginList class is an array, enhanced to allow access to loaded plugins by name, and iteration over loaded plugins in order of priority. This array is used by Engines::RailsExtensions::RailsInitializer to create the Engines.plugins array.
Each loaded plugin has a corresponding Plugin instance within this array, and the order the plugins were loaded is reflected in the entries in this array.
For more information, see the Rails module.
Defined Under Namespace
Modules: Assets, Testing Classes: Plugin
Class Method Summary
- + (Object) init(initializer)
- + (Object) load_extensions
- + (Object) logger
-
+ (Object) mirror_files_from(source, destination)
A general purpose method to mirror a directory (source) into a destination directory, including all files and subdirectories.
-
+ (Object) mix_code_from(*types)
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.
- + (Object) select_existing_paths(paths)
Class Method Details
+ (Object) init(initializer)
84 85 86 87 |
# File 'vendor/plugins/engines/lib/engines.rb', line 84 def init(initializer) load_extensions Engines::Assets.initialize_base_public_directory end |
+ (Object) load_extensions
93 94 95 96 97 |
# File 'vendor/plugins/engines/lib/engines.rb', line 93 def load_extensions rails_extensions.each { |name| require "engines/rails_extensions/#{name}" } # load the testing extensions, if we are in the test environment. require "engines/testing" if RAILS_ENV == "test" end |
+ (Object) logger
89 90 91 |
# File 'vendor/plugins/engines/lib/engines.rb', line 89 def logger RAILS_DEFAULT_LOGGER end |
+ (Object) mirror_files_from(source, destination)
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?).
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'vendor/plugins/engines/lib/engines.rb', line 138 def mirror_files_from(source, destination) return unless File.directory?(source) # TODO: use Rake::FileList#pathmap? source_files = Dir[source + "/**/*"] source_dirs = source_files.select { |d| File.directory?(d) } source_files -= source_dirs unless source_files.empty? base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, '')) FileUtils.mkdir_p(base_target_dir) end source_dirs.each do |dir| # strip down these paths so we have simple, relative paths we can # add to the destination target_dir = File.join(destination, dir.gsub(source, '')) begin FileUtils.mkdir_p(target_dir) rescue Exception => e raise "Could not create directory #{target_dir}: \n" + e end end source_files.each do |file| begin target = File.join(destination, file.gsub(source, '')) unless File.exist?(target) && FileUtils.identical?(file, target) FileUtils.cp(file, target) end rescue Exception => e raise "Could not copy #{file} to #{target}: \n" + e end end end |
+ (Object) mix_code_from(*types)
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 by including them in Rails load path mechanism, e.g. in init.rb:
ActiveSupport::Dependencies.load_paths << File.join(File.dirname(__FILE__), 'app', 'things'))
131 132 133 |
# File 'vendor/plugins/engines/lib/engines.rb', line 131 def mix_code_from(*types) self.code_mixing_file_types += types.map { |x| x.to_s.singularize } end |
+ (Object) select_existing_paths(paths)
99 100 101 |
# File 'vendor/plugins/engines/lib/engines.rb', line 99 def select_existing_paths(paths) paths.select { |path| File.directory?(path) } end |