Class: Rails::Plugin
Overview
Rails::Plugin is nothing more than a Rails::Engine, but since it's loaded too late in the boot process, it does not have the same configuration powers as a bare Rails::Engine.
Opposite to Rails::Railtie and Rails::Engine, you are not supposed to inherit from Rails::Plugin. Rails::Plugin is automatically configured to be an engine by simply placing inside vendor/plugins. Since this is done automatically, you actually cannot declare a Rails::Engine inside your Plugin, otherwise it would cause the same files to be loaded twice. This means that if you want to ship an Engine as gem it cannot be used as plugin and vice-versa.
Besides this conceptual difference, the only difference between Rails::Engine and Rails::Plugin is that plugins automatically load the file "init.rb" at the plugin root during the boot process.
Constant Summary
Constant Summary
Constants inherited from Railtie
Instance Attribute Summary (collapse)
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) path
readonly
Returns the value of attribute path.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) config
-
- (Plugin) initialize(root)
constructor
A new instance of Plugin.
- - (Object) railtie_name
Methods inherited from Engine
#app, #call, #eager_load!, endpoint, #endpoint, #env_config, find, #helpers, #helpers_paths, #initializers, isolate_namespace, #load_console, #load_generators, #load_seed, #load_tasks, #ordered_railties, #railties, #routes, #routes_url_helpers
Methods inherited from Railtie
abstract_railtie?, console, #eager_load!, generators, #load_console, #load_generators, #load_tasks, railtie_name, #railtie_namespace, rake_tasks, subclasses
Methods included from Initializable
included, #initializers, #run_initializers
Constructor Details
- (Plugin) initialize(root)
A new instance of Plugin
55 56 57 58 59 |
# File 'railties/lib/rails/plugin.rb', line 55 def initialize(root) ActiveSupport::Deprecation.warn "You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released" @name = File.basename(root).to_sym config.root = root end |
Instance Attribute Details
- (Object) name (readonly)
Returns the value of attribute name
49 50 51 |
# File 'railties/lib/rails/plugin.rb', line 49 def name @name end |
- (Object) path (readonly)
Returns the value of attribute path
49 50 51 |
# File 'railties/lib/rails/plugin.rb', line 49 def path @path end |
Class Method Details
+ (Object) all(list, paths)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'railties/lib/rails/plugin.rb', line 29 def self.all(list, paths) plugins = [] paths.each do |path| Dir["#{path}/*"].each do |plugin_path| plugin = new(plugin_path) next unless list.include?(plugin.name) || list.include?(:all) if global_plugins.include?(plugin.name) warn "WARNING: plugin #{plugin.name} from #{path} was not loaded. Plugin with the same name has been already loaded." next end global_plugins << plugin.name plugins << plugin end end plugins.sort_by do |p| [list.index(p.name) || list.index(:all), p.name.to_s] end end |
+ (Object) global_plugins
21 22 23 |
# File 'railties/lib/rails/plugin.rb', line 21 def self.global_plugins @global_plugins ||= [] end |
+ (Object) inherited(base)
25 26 27 |
# File 'railties/lib/rails/plugin.rb', line 25 def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end |