Class: Rails::Plugin

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/rails/plugin.rb,
lib/rails/plugin/loader.rb,
lib/rails/plugin/locator.rb

Overview

The Plugin class should be an object which provides the following methods:

  • name - Used during initialisation to order the plugin (based on name and

    the contents of <tt>config.plugins</tt>).
    
  • valid? - Returns true if this plugin can be loaded.

  • load_paths - Each path within the returned array will be added to the $LOAD_PATH.

  • load - Finally ‘load’ the plugin.

These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes. The default implementation returns the lib directory as its load_paths, and evaluates init.rb when load is called.

You can also inspect the about.yml data programmatically:

plugin = Rails::Plugin.new(path_to_my_plugin)
plugin.about["author"] # => "James Adam"
plugin.about["url"] # => "http://interblah.net"

Direct Known Subclasses

GemPlugin

Defined Under Namespace

Classes: FileSystemLocator, GemLocator, Loader, Locator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Plugin

Returns a new instance of Plugin.



24
25
26
27
28
# File 'lib/rails/plugin.rb', line 24

def initialize(directory)
  @directory = directory
  @name      = File.basename(@directory) rescue nil
  @loaded    = false
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



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

def directory
  @directory
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#<=>(other_plugin) ⇒ Object



52
53
54
# File 'lib/rails/plugin.rb', line 52

def <=>(other_plugin)
  name <=> other_plugin.name
end

#aboutObject



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

def about
  @about ||= load_about_information
end

#load(initializer) ⇒ Object

Evaluates a plugin’s init.rb file.



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

def load(initializer)
  return if loaded?
  report_nonexistant_or_empty_plugin! unless valid?
  evaluate_init_rb(initializer)
  @loaded = true
end

#load_pathsObject

Returns a list of paths this plugin wishes to make available in $LOAD_PATH.



35
36
37
38
# File 'lib/rails/plugin.rb', line 35

def load_paths
  report_nonexistant_or_empty_plugin! unless valid?
  has_lib_directory? ? [lib_path] : []
end

#loaded?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rails/plugin.rb', line 48

def loaded?
  @loaded
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rails/plugin.rb', line 30

def valid?
  File.directory?(directory) && (has_lib_directory? || has_init_file?)
end