Class: Puma::PluginRegistry
- Inherits:
-
Object
- Object
- Puma::PluginRegistry
- Defined in:
- lib/puma/plugin.rb
Instance Method Summary collapse
- #add_background(blk) ⇒ Object
- #find(name) ⇒ Object
- #fire_background ⇒ Object
-
#initialize ⇒ PluginRegistry
constructor
A new instance of PluginRegistry.
- #register(name, cls) ⇒ Object
Constructor Details
#initialize ⇒ PluginRegistry
Returns a new instance of PluginRegistry.
31 32 33 34 |
# File 'lib/puma/plugin.rb', line 31 def initialize @plugins = {} @background = [] end |
Instance Method Details
#add_background(blk) ⇒ Object
60 61 62 |
# File 'lib/puma/plugin.rb', line 60 def add_background(blk) @background << blk end |
#find(name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puma/plugin.rb', line 40 def find(name) name = name.to_s if cls = @plugins[name] return cls end begin require "puma/plugin/#{name}" rescue LoadError raise UnknownPlugin, "Unable to find plugin: #{name}" end if cls = @plugins[name] return cls end raise UnknownPlugin, "file failed to register a plugin" end |
#fire_background ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/puma/plugin.rb', line 64 def fire_background @background.each_with_index do |b, i| Thread.new do Puma.set_thread_name "plugin background #{i}" b.call end end end |
#register(name, cls) ⇒ Object
36 37 38 |
# File 'lib/puma/plugin.rb', line 36 def register(name, cls) @plugins[name] = cls end |