Class: Lich::Common::UpstreamHook
- Inherits:
-
Object
- Object
- Lich::Common::UpstreamHook
- Defined in:
- documented/common/upstreamhook.rb
Overview
Handles upstream hooks for the Lich project. This class allows adding, running, removing, and listing hooks that can modify client strings.
Class Method Summary collapse
-
.add(name, action) ⇒ Boolean
Adds a new upstream hook.
-
.hook_sources ⇒ Hash<String, String>
Retrieves the hash of upstream hook sources.
-
.list ⇒ Array<String>
Lists all registered upstream hooks.
-
.remove(name) ⇒ void
Removes an upstream hook by name.
-
.run(client_string) ⇒ String?
Runs all registered upstream hooks in order.
-
.sources ⇒ String
Displays the sources of all registered upstream hooks in a table format.
Class Method Details
.add(name, action) ⇒ Boolean
Adds a new upstream hook.
23 24 25 26 27 28 29 30 |
# File 'documented/common/upstreamhook.rb', line 23 def UpstreamHook.add(name, action) unless action.is_a?(Proc) echo "UpstreamHook: not a Proc (#{action})" return false end @@upstream_hook_sources[name] = (Script.current.name || "Unknown") @@upstream_hooks[name] = action end |
.hook_sources ⇒ Hash<String, String>
Retrieves the hash of upstream hook sources.
85 86 87 |
# File 'documented/common/upstreamhook.rb', line 85 def UpstreamHook.hook_sources @@upstream_hook_sources end |
.list ⇒ Array<String>
Lists all registered upstream hooks.
66 67 68 |
# File 'documented/common/upstreamhook.rb', line 66 def UpstreamHook.list @@upstream_hooks.keys.dup end |
.remove(name) ⇒ void
This method returns an undefined value.
Removes an upstream hook by name.
57 58 59 60 |
# File 'documented/common/upstreamhook.rb', line 57 def UpstreamHook.remove(name) @@upstream_hook_sources.delete(name) @@upstream_hooks.delete(name) end |
.run(client_string) ⇒ String?
Runs all registered upstream hooks in order.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'documented/common/upstreamhook.rb', line 38 def UpstreamHook.run(client_string) for key in @@upstream_hooks.keys begin client_string = @@upstream_hooks[key].call(client_string) rescue @@upstream_hooks.delete(key) respond "--- Lich: UpstreamHook: #{$!}" respond $!.backtrace.first end return nil if client_string.nil? end return client_string end |
.sources ⇒ String
Displays the sources of all registered upstream hooks in a table format.
74 75 76 77 78 79 |
# File 'documented/common/upstreamhook.rb', line 74 def UpstreamHook.sources info_table = Terminal::Table.new :headings => ['Hook', 'Source'], :rows => @@upstream_hook_sources.to_a, :style => { :all_separators => true } Lich::Messaging.mono(info_table.to_s) end |