GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/zmack/mephisto.git
svenfuchs (author)
Wed Feb 20 11:11:20 -0800 2008
commit  1ad1b56b4a6c9284534b0afbb9d5d87715ae4312
tree    adc435b61f05728a991fd314188bc3e75cfb6038
parent  2772ec18227b04b3cb618748a2900a7b93b84d94
mephisto / vendor / plugins / engines / lib / engines / plugin / list.rb
100644 30 lines (29 sloc) 1.172 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# The PluginList class is an array, enhanced to allow access to loaded plugins
# by name, and iteration over loaded plugins in order of priority. This array is used
# by Engines::RailsExtensions::RailsInitializer to create the Engines.plugins array.
#
# Each loaded plugin has a corresponding Plugin instance within this array, and
# the order the plugins were loaded is reflected in the entries in this array.
#
# For more information, see the Rails module.
module Engines
  class Plugin
    class List < Array
      # Finds plugins with the set with the given name (accepts Strings or Symbols), or
      # index. So, Engines.plugins[0] returns the first-loaded Plugin, and Engines.plugins[:engines]
      # returns the Plugin instance for the engines plugin itself.
      def [](name_or_index)
        if name_or_index.is_a?(Fixnum)
          super
        else
          self.find { |plugin| plugin.name.to_s == name_or_index.to_s }
        end
      end
  
      # Go through each plugin, highest priority first (last loaded first). Effectively,
      # this is like <tt>Engines.plugins.reverse</tt>
      def by_precedence
        reverse
      end
    end
  end
end