Class: Chocomint::Tools::Registry
- Inherits:
-
Object
- Object
- Chocomint::Tools::Registry
- Defined in:
- lib/chocomint/tools/registry.rb
Overview
ツール名 -> インスタンスの解決 (DESIGN §14: 未知ツールは FAIL)。
Instance Method Summary collapse
- #all ⇒ Object
- #fetch(name) ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(tool) ⇒ Object
- #tool_definitions ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
9 10 11 |
# File 'lib/chocomint/tools/registry.rb', line 9 def initialize @tools = {} end |
Instance Method Details
#all ⇒ Object
24 |
# File 'lib/chocomint/tools/registry.rb', line 24 def all = @tools.values |
#fetch(name) ⇒ Object
18 19 20 |
# File 'lib/chocomint/tools/registry.rb', line 18 def fetch(name) @tools[name] or raise UnknownToolError, "unknown tool: #{name}" end |
#include?(name) ⇒ Boolean
22 |
# File 'lib/chocomint/tools/registry.rb', line 22 def include?(name) = @tools.key?(name) |
#register(tool) ⇒ Object
13 14 15 16 |
# File 'lib/chocomint/tools/registry.rb', line 13 def register(tool) @tools[tool.name] = tool self end |
#tool_definitions ⇒ Object
26 |
# File 'lib/chocomint/tools/registry.rb', line 26 def tool_definitions = all.map(&:to_tool_definition) |