Class: Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/loaded_plugins/plugin.rb

Overview

An instance of Plugin is created for each plugin loaded by Rails, and stored in the Rails.plugins list

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Plugin

:nodoc:



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

def initialize(root) #:nodoc:
  root.chop! if root.ends_with?('/')
  
  @root = root
  @name = self.class.name_for(root)
end

Instance Attribute Details

#nameObject

The name of this plugin



5
6
7
# File 'lib/loaded_plugins/plugin.rb', line 5

def name
  @name
end

#rootObject

The directory in which this plugin is located



8
9
10
# File 'lib/loaded_plugins/plugin.rb', line 8

def root
  @root
end

Class Method Details

.name_for(path) ⇒ Object

Gets the name of the plugin, given the path to it. The following would return “plugin_xyz”:

  • plugin_xyz

  • plugin_xyz-1.2

  • plugin_xyz-1.2.0

  • plugin_xyz-1.2.0-win32



17
18
19
20
# File 'lib/loaded_plugins/plugin.rb', line 17

def name_for(path)
  name = File.basename(path)
  /^(.+)-#{Gem::Version::NUM_RE}(-.+)?$/.match(name) && $1 || name
end

Instance Method Details

#==(other_obj) ⇒ Object

:nodoc:



70
71
72
73
74
75
76
# File 'lib/loaded_plugins/plugin.rb', line 70

def ==(other_obj) #:nodoc:
  if other_obj.is_a?(Plugin)
    other_obj.name == name
  else
    other_obj.to_s == name
  end
end

#after_initializeObject

Invoked during the Rails::Initializer#after_initialize callback



67
68
# File 'lib/loaded_plugins/plugin.rb', line 67

def after_initialize
end

#after_loadObject

Invoked immediately after Rails::Initializer loads the plugin



63
64
# File 'lib/loaded_plugins/plugin.rb', line 63

def after_load
end

#before_loadObject

Invoked immediately before Rails::Initializer loads the plugin



59
60
# File 'lib/loaded_plugins/plugin.rb', line 59

def before_load
end

#lib_pathObject

The path to the plugin’s lib folder



31
32
33
# File 'lib/loaded_plugins/plugin.rb', line 31

def lib_path
  "#{root}/lib"
end

#lib_path?Boolean

Does the plugin’s lib path exist?

Returns:

  • (Boolean)


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

def lib_path?
  File.exists?(lib_path)
end

#plugins_afterObject

Gets all of the plugins that were loaded after this one



50
51
52
53
54
55
56
# File 'lib/loaded_plugins/plugin.rb', line 50

def plugins_after
  if Rails.plugins.last == self
    []
  else
    Rails.plugins[Rails.plugins.index(self)+1..Rails.plugins.length-1]
  end
end

#plugins_beforeObject

Gets all of the plugins that were loaded before this one



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

def plugins_before
  if Rails.plugins.first == self
    []
  else
    Rails.plugins[0..Rails.plugins.index(self)-1]
  end
end