Class: Rails::Plugin

Inherits:
Engine show all
Defined in:
lib/rails/plugin.rb

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

Constants inherited from Railtie

Railtie::ABSTRACT_RAILTIES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Engine

#eager_load!, find_root_with_flag

Methods inherited from Railtie

abstract_railtie?, console, #eager_load!, generators, #load_console, #load_generators, log_subscriber, railtie_name, rake_tasks, subclasses

Methods included from Initializable

included, #initializers, #run_initializers

Constructor Details

#initialize(root) ⇒ Plugin

Returns a new instance of Plugin.



55
56
57
58
# File 'lib/rails/plugin.rb', line 55

def initialize(root)
  @name = File.basename(root).to_sym
  config.root = root
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/rails/plugin.rb', line 40

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



40
41
42
# File 'lib/rails/plugin.rb', line 40

def path
  @path
end

Class Method Details

.all(list, paths) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails/plugin.rb', line 25

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)
      plugins << plugin
    end
  end

  plugins.sort_by do |p|
    [list.index(p.name) || list.index(:all), p.name.to_s]
  end
end

.inherited(base) ⇒ Object



21
22
23
# File 'lib/rails/plugin.rb', line 21

def self.inherited(base)
  raise "You cannot inherit from Rails::Plugin"
end

Instance Method Details

#configObject



60
61
62
# File 'lib/rails/plugin.rb', line 60

def config
  @config ||= Engine::Configuration.new
end

#load_deprecated_tasksObject



47
48
49
50
51
52
53
# File 'lib/rails/plugin.rb', line 47

def load_deprecated_tasks
  tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"].sort
  if tasks.any?
    ActiveSupport::Deprecation.warn "Rake tasks in #{tasks.to_sentence} are deprecated. Use lib/tasks instead"
    tasks.each { |ext| load(ext) }
  end
end

#load_tasksObject



42
43
44
45
# File 'lib/rails/plugin.rb', line 42

def load_tasks
  super
  load_deprecated_tasks
end