Class
PhusionPassenger::Plugin

In: | lib/phusion_passenger/plugin.rb
Parent: | Object

Methods

- call_hook
- call_hook
- load
- new
- register
- register_hook

Public Class methods
call_hook(name, *args, &block)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 56
    56:         def self.call_hook(name, *args, &block)
    57:                 last_result = nil
    58:                 if (hooks_list = @@hooks[name])
    59:                         hooks_list.each do |callback|
    60:                                 last_result = callback.call(*args, &block)
    61:                         end
    62:                 end
    63:                 return last_result
    64:         end

load(name, load_once = true)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 33
    33:         def self.load(name, load_once = true)
    34:                 PLUGIN_DIRS.each do |plugin_dir|
    35:                         if plugin_dir =~ /\A~/
    36:                                 # File.expand_path uses ENV['HOME'] which we don't want.
    37:                                 home = Etc.getpwuid(Process.uid).dir
    38:                                 plugin_dir = plugin_dir.sub(/\A~/, home)
    39:                         end
    40:                         plugin_dir = File.expand_path(plugin_dir)
    41:                         Dir["#{plugin_dir}/*/#{name}.rb"].each do |filename|
    42:                                 if load_once
    43:                                         require(filename)
    44:                                 else
    45:                                         load(filename)
    46:                                 end
    47:                         end
    48:                 end
    49:         end

new(name, *args, &block)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 71
    71:         def initialize(name, *args, &block)
    72:                 Plugin.load(name)
    73:                 classes = @@classes[name]
    74:                 if classes
    75:                         @instances = classes.map do |klass|
    76:                                 klass.new(*args, &block)
    77:                         end
    78:                 else
    79:                         return nil
    80:                 end
    81:         end

register(name, klass)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 66
    66:         def self.register(name, klass)
    67:                 classes = (@@classes[name] ||= [])
    68:                 classes << klass
    69:         end

register_hook(name, &block)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 51
    51:         def self.register_hook(name, &block)
    52:                 hooks_list = (@@hooks[name] ||= [])
    53:                 hooks_list << block
    54:         end

Public Instance methods
call_hook(name, *args, &block)

[ show source ]

        # File lib/phusion_passenger/plugin.rb, line 83
    83:         def call_hook(name, *args, &block)
    84:                 last_result = nil
    85:                 if @instances
    86:                         @instances.each do |instance|
    87:                                 if instance.respond_to?(name.to_sym)
    88:                                         last_result = instance.__send__(name.to_sym, *args, &block)
    89:                                 end
    90:                         end
    91:                 end
    92:                 return last_result
    93:         end