Module: AIA::Directives::Registry
- Defined in:
- lib/aia/directives/registry.rb
Constant Summary collapse
- EXCLUDED_METHODS =
%w[ run initialize private? ]
Class Method Summary collapse
- .aliases ⇒ Object
- .build_aliases(private_methods) ⇒ Object
- .desc(description, method_name = nil) ⇒ Object
- .descriptions ⇒ Object
- .directive?(string) ⇒ Boolean
- .method_added(method_name) ⇒ Object
- .prefix_size ⇒ Object
- .process(directive_name, args, context_manager) ⇒ Object
- .register_directive_module(mod) ⇒ Object
- .run(directives) ⇒ Object
Class Method Details
.aliases ⇒ Object
20 21 22 |
# File 'lib/aia/directives/registry.rb', line 20 def aliases @aliases ||= {} end |
.build_aliases(private_methods) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/aia/directives/registry.rb', line 38 def build_aliases(private_methods) private_methods.each do |method_name| method = instance_method(method_name) aliases[method_name] = [] private_methods.each do |other_method_name| next if method_name == other_method_name other_method = instance_method(other_method_name) if method == other_method aliases[method_name] << other_method_name end end end end |
.desc(description, method_name = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/aia/directives/registry.rb', line 24 def desc(description, method_name = nil) @last_description = description descriptions[method_name.to_s] = description if method_name nil end |
.descriptions ⇒ Object
16 17 18 |
# File 'lib/aia/directives/registry.rb', line 16 def descriptions @descriptions ||= {} end |
.directive?(string) ⇒ Boolean
102 103 104 105 106 107 108 109 110 |
# File 'lib/aia/directives/registry.rb', line 102 def directive?(string) content = if string.is_a?(RubyLLM::Message) string.content rescue string.to_s else string.to_s end content.strip.start_with?(PromptManager::Prompt::DIRECTIVE_SIGNAL) end |
.method_added(method_name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/aia/directives/registry.rb', line 30 def method_added(method_name) if @last_description descriptions[method_name.to_s] = @last_description @last_description = nil end super if defined?(super) end |
.prefix_size ⇒ Object
98 99 100 |
# File 'lib/aia/directives/registry.rb', line 98 def prefix_size PromptManager::Prompt::DIRECTIVE_SIGNAL.size end |
.process(directive_name, args, context_manager) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/aia/directives/registry.rb', line 61 def process(directive_name, args, context_manager) if EXCLUDED_METHODS.include?(directive_name) return "Error: #{directive_name} is not a valid directive" end # Check all registered directive modules @directive_modules ||= [] @directive_modules.each do |mod| if mod.respond_to?(directive_name) return mod.send(directive_name, args, context_manager) end end return "Error: Unknown directive '#{directive_name}'" end |
.register_directive_module(mod) ⇒ Object
56 57 58 59 |
# File 'lib/aia/directives/registry.rb', line 56 def register_directive_module(mod) @directive_modules ||= [] @directive_modules << mod end |
.run(directives) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/aia/directives/registry.rb', line 77 def run(directives) return {} if directives.nil? || directives.empty? directives.each do |key, _| sans_prefix = key[prefix_size..] args = sans_prefix.split(' ') method_name = args.shift.downcase if EXCLUDED_METHODS.include?(method_name) directives[key] = "Error: #{method_name} is not a valid directive: #{key}" next elsif respond_to?(method_name, true) directives[key] = send(method_name, args) else directives[key] = "Error: Unknown directive '#{key}'" end end directives end |