summaryrefslogtreecommitdiffhomepage
path: root/lib/dispatch/tools/registry.rb
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-03-31 21:36:46 +0900
committerAdam Malczewski <[email protected]>2026-03-31 21:36:46 +0900
commit6b6e158d0614806dc970f7307fb63d392f0cb976 (patch)
treeea19a4ccfe97b05b17a3418461daebb1d0543505 /lib/dispatch/tools/registry.rb
parent7221a9d38fcd29d89794bc3041f11c5358b3155e (diff)
downloaddispatch-tools-interface-6b6e158d0614806dc970f7307fb63d392f0cb976.tar.gz
dispatch-tools-interface-6b6e158d0614806dc970f7307fb63d392f0cb976.zip
imp
Diffstat (limited to 'lib/dispatch/tools/registry.rb')
-rw-r--r--lib/dispatch/tools/registry.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/dispatch/tools/registry.rb b/lib/dispatch/tools/registry.rb
new file mode 100644
index 0000000..e4a5d3e
--- /dev/null
+++ b/lib/dispatch/tools/registry.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+module Dispatch
+ module Tools
+ class Registry
+ def initialize
+ @tools = {}
+ end
+
+ def register(tool_definition)
+ name = tool_definition.name
+
+ if @tools.key?(name)
+ raise DuplicateToolError, "Tool '#{name}' is already registered"
+ end
+
+ @tools[name] = tool_definition
+ self
+ end
+
+ def get(name)
+ @tools.fetch(name) do
+ raise ToolNotFoundError, "Tool '#{name}' not found"
+ end
+ end
+
+ def has?(name)
+ @tools.key?(name)
+ end
+
+ def tools
+ @tools.values
+ end
+
+ def tool_names
+ @tools.keys
+ end
+
+ def to_a
+ @tools.values.map(&:to_tool_definition)
+ end
+
+ def subset(*names)
+ new_registry = self.class.new
+
+ names.each do |name|
+ new_registry.register(get(name))
+ end
+
+ new_registry
+ end
+
+ def size
+ @tools.size
+ end
+
+ def empty?
+ @tools.empty?
+ end
+ end
+ end
+end