Module: Engines::PluginExtension
Class Method Summary collapse
Instance Method Summary collapse
- #add_plugin_view_paths ⇒ Object
- #initialize_with_default_paths(*args) ⇒ Object
-
#latest_migration ⇒ Object
Returns the version number of the latest migration for this plugin.
-
#load(initializer) ⇒ Object
Extends the superclass’ load method to additionally mirror public assets.
-
#load_paths ⇒ Object
Returns a list of paths this plugin wishes to make available in $LOAD_PATH.
-
#migrate(version = nil) ⇒ Object
Migrate this plugin to the given version.
-
#migration_directory ⇒ Object
The directory containing this plugin’s migrations (
plugin/db/migrate). -
#public_asset_directory ⇒ Object
The path to this plugin’s public files.
-
#routes_path ⇒ Object
The path to this plugin’s routes file.
-
#select_existing_paths(name) ⇒ Object
for code_paths and controller_paths select those paths that actually exist in the plugin’s directory.
Class Method Details
.included(base) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/engines/plugin.rb', line 16 def self.included(base) # Plugins can add code paths to this attribute in init.rb if they # need plugin directories to be added to the load path, i.e. # # plugin.code_paths << 'app/other_classes' # # Defaults to ["app/controllers", "app/helpers", "app/models", "components"] base.send :attr_accessor, :code_paths # Plugins can add paths to this attribute in init.rb if they need # controllers loaded from additional locations. base.send :attr_accessor, :controller_paths # The directory in this plugin to mirror into the shared directory # under +public+. # # Defaults to "assets" (see default_public_directory). base.send :attr_accessor, :public_directory base.alias_method_chain :initialize, :default_paths end |
Instance Method Details
#add_plugin_view_paths ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/engines/plugin.rb', line 96 def add_plugin_view_paths view_path = File.join(directory, 'app', 'views') if File.exist?(view_path) ActionController::Base.view_paths.insert(1, view_path) # push it just underneath the app ActionView::TemplateFinder.process_view_paths(view_path) end end |
#initialize_with_default_paths(*args) ⇒ Object
69 70 71 72 |
# File 'lib/engines/plugin.rb', line 69 def initialize_with_default_paths(*args) initialize_without_default_paths(*args) initialize_default_paths end |
#latest_migration ⇒ Object
Returns the version number of the latest migration for this plugin. Returns nil if this plugin has no migrations.
121 122 123 124 125 |
# File 'lib/engines/plugin.rb', line 121 def latest_migration migrations = Dir[migration_directory+"/*.rb"] return nil if migrations.empty? migrations.map { |p| File.basename(p) }.sort.last.match(/0*(\d+)\_/)[1].to_i end |
#load(initializer) ⇒ Object
Extends the superclass’ load method to additionally mirror public assets
83 84 85 86 87 88 |
# File 'lib/engines/plugin.rb', line 83 def load(initializer) return if loaded? super initializer add_plugin_view_paths Assets.mirror_files_for(self) end |
#load_paths ⇒ Object
Returns a list of paths this plugin wishes to make available in $LOAD_PATH
Overwrites the correspondend method in the superclass
77 78 79 80 |
# File 'lib/engines/plugin.rb', line 77 def load_paths report_nonexistant_or_empty_plugin! unless valid? select_existing_paths :code_paths end |
#migrate(version = nil) ⇒ Object
Migrate this plugin to the given version. See Engines::Plugin::Migrator for more information.
129 130 131 |
# File 'lib/engines/plugin.rb', line 129 def migrate(version = nil) Engines::Plugin::Migrator.migrate_plugin(self, version) end |
#migration_directory ⇒ Object
The directory containing this plugin’s migrations (plugin/db/migrate)
115 116 117 |
# File 'lib/engines/plugin.rb', line 115 def migration_directory File.join(self.directory, 'db', 'migrate') end |
#public_asset_directory ⇒ Object
The path to this plugin’s public files
105 106 107 |
# File 'lib/engines/plugin.rb', line 105 def public_asset_directory "#{File.basename(Engines.public_directory)}/#{name}" end |
#routes_path ⇒ Object
The path to this plugin’s routes file
110 111 112 |
# File 'lib/engines/plugin.rb', line 110 def routes_path File.join(directory, "routes.rb") end |
#select_existing_paths(name) ⇒ Object
for code_paths and controller_paths select those paths that actually exist in the plugin’s directory
92 93 94 |
# File 'lib/engines/plugin.rb', line 92 def select_existing_paths(name) Engines.select_existing_paths(self.send(name).map { |p| File.join(directory, p) }) end |