Class: Lich::Common::DownstreamHook
- Inherits:
-
Object
- Object
- Lich::Common::DownstreamHook
- Defined in:
- lib/common/downstreamhook.rb
Overview
A class that manages downstream hooks for processing strings.
Class Method Summary collapse
-
.add(name, action) ⇒ Boolean
Adds a new downstream hook with a given name and action.
-
.hook_sources ⇒ Hash
Retrieves the sources of all registered downstream hooks.
-
.list ⇒ Array<String>
Lists all registered downstream hooks.
-
.remove(name) ⇒ nil
Removes a downstream hook by its name.
-
.run(server_string) ⇒ String?
Runs all registered downstream hooks on the provided server string.
-
.sources ⇒ String
Displays the sources of all registered downstream hooks in a table format.
Class Method Details
.add(name, action) ⇒ Boolean
Adds a new downstream hook with a given name and action.
18 19 20 21 22 23 24 25 |
# File 'lib/common/downstreamhook.rb', line 18 def DownstreamHook.add(name, action) unless action.class == Proc echo "DownstreamHook: not a Proc (#{action})" return false end @@downstream_hook_sources[name] = (Script.current.name || "Unknown") @@downstream_hooks[name] = action end |
.hook_sources ⇒ Hash
Retrieves the sources of all registered downstream hooks.
85 86 87 |
# File 'lib/common/downstreamhook.rb', line 85 def DownstreamHook.hook_sources @@downstream_hook_sources end |
.list ⇒ Array<String>
Lists all registered downstream hooks.
64 65 66 |
# File 'lib/common/downstreamhook.rb', line 64 def DownstreamHook.list @@downstream_hooks.keys.dup end |
.remove(name) ⇒ nil
Removes a downstream hook by its name.
54 55 56 57 |
# File 'lib/common/downstreamhook.rb', line 54 def DownstreamHook.remove(name) @@downstream_hook_sources.delete(name) @@downstream_hooks.delete(name) end |
.run(server_string) ⇒ String?
Runs all registered downstream hooks on the provided server string.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/common/downstreamhook.rb', line 34 def DownstreamHook.run(server_string) for key in @@downstream_hooks.keys return nil if server_string.nil? begin server_string = @@downstream_hooks[key].call(server_string.dup) if server_string.is_a?(String) rescue @@downstream_hooks.delete(key) respond "--- Lich: DownstreamHook: #{$!}" respond $!.backtrace.first end end return server_string end |
.sources ⇒ String
Displays the sources of all registered downstream hooks in a table format.
73 74 75 76 77 78 |
# File 'lib/common/downstreamhook.rb', line 73 def DownstreamHook.sources info_table = Terminal::Table.new :headings => ['Hook', 'Source'], :rows => @@downstream_hook_sources.to_a, :style => { :all_separators => true } Lich::Messaging.mono(info_table.to_s) end |