To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / engines / lib / engines / plugin / list.rb @ 442:753f1380d6bc

History | View | Annotate | Download (1.14 KB)

1
# The PluginList class is an array, enhanced to allow access to loaded plugins
2
# by name, and iteration over loaded plugins in order of priority. This array is used
3
# by Engines::RailsExtensions::RailsInitializer to create the Engines.plugins array.
4
#
5
# Each loaded plugin has a corresponding Plugin instance within this array, and 
6
# the order the plugins were loaded is reflected in the entries in this array.
7
#
8
# For more information, see the Rails module.
9
module Engines
10
  class Plugin
11
    class List < Array
12
      # Finds plugins with the set with the given name (accepts Strings or Symbols), or
13
      # index. So, Engines.plugins[0] returns the first-loaded Plugin, and Engines.plugins[:engines]
14
      # returns the Plugin instance for the engines plugin itself.
15
      def [](name_or_index)
16
        if name_or_index.is_a?(Fixnum)
17
          super
18
        else
19
          self.find { |plugin| plugin.name.to_s == name_or_index.to_s }
20
        end
21
      end
22
  
23
      # Go through each plugin, highest priority first (last loaded first). Effectively,
24
      # this is like <tt>Engines.plugins.reverse</tt>
25
      def by_precedence
26
        reverse
27
      end
28
    end
29
  end
30
end