Class: Envoy::Toolset
- Inherits:
-
Object
- Object
- Envoy::Toolset
- Defined in:
- lib/envoy/toolset.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#description(text = nil) ⇒ Object
Reader returns this toolset's own description followed by each composed toolset's (so the model understands every tool group); setter records it.
-
#initialize(key) ⇒ Toolset
constructor
A new instance of Toolset.
- #tool(name, &block) ⇒ Object
-
#tools_for(read_only: false) ⇒ Object
This toolset's own tools plus every composed toolset's, de-duplicated by name (own tools win, then composed in
useorder). -
#use(*keys) ⇒ Object
Compose other toolsets into this one.
Constructor Details
#initialize(key) ⇒ Toolset
Returns a new instance of Toolset.
5 6 7 8 9 10 |
# File 'lib/envoy/toolset.rb', line 5 def initialize(key) @key = key.to_s @description = "" @tools = {} @composed_keys = [] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/envoy/toolset.rb', line 3 def key @key end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
3 4 5 |
# File 'lib/envoy/toolset.rb', line 3 def tools @tools end |
Instance Method Details
#description(text = nil) ⇒ Object
Reader returns this toolset's own description followed by each composed toolset's (so the model understands every tool group); setter records it.
14 15 16 17 |
# File 'lib/envoy/toolset.rb', line 14 def description(text = nil) return @description = text unless text.nil? collect_descriptions.compact_blank.join("\n\n") end |
#tool(name, &block) ⇒ Object
19 20 21 22 23 |
# File 'lib/envoy/toolset.rb', line 19 def tool(name, &block) definition = ToolDefinition.new(name) definition.instance_eval(&block) @tools[definition.name] = definition end |
#tools_for(read_only: false) ⇒ Object
This toolset's own tools plus every composed toolset's, de-duplicated by
name (own tools win, then composed in use order). read_only strips write
tools across the merged set (governance lever for embeds).
35 36 37 38 |
# File 'lib/envoy/toolset.rb', line 35 def tools_for(read_only: false) list = collect_tools.values read_only ? list.select(&:read?) : list end |
#use(*keys) ⇒ Object
Compose other toolsets into this one. Keys are resolved lazily (at tools_for / description time via Envoy.toolset), so the load order of toolset definitions does not matter.
28 29 30 |
# File 'lib/envoy/toolset.rb', line 28 def use(*keys) @composed_keys.concat(keys.map(&:to_s)) end |