Module: VSM::Meta
- Defined in:
- lib/vsm/meta.rb,
lib/vsm/meta/tools.rb,
lib/vsm/meta/support.rb,
lib/vsm/meta/snapshot_cache.rb,
lib/vsm/meta/snapshot_builder.rb
Defined Under Namespace
Modules: Support, Tools
Classes: SnapshotBuilder, SnapshotCache
Constant Summary
collapse
- DEFAULT_TOOL_MAP =
{
"meta_summarize_self" => Tools::SummarizeSelf,
"meta_list_tools" => Tools::ListTools,
"meta_explain_tool" => Tools::ExplainTool,
"meta_explain_role" => Tools::ExplainRole
}.freeze
Class Method Summary
collapse
Class Method Details
.attach!(capsule, prefix: "", only: nil, except: nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/vsm/meta.rb', line 19
def attach!(capsule, prefix: "", only: nil, except: nil)
cache = SnapshotCache.new(SnapshotBuilder.new(root: capsule))
installed = {}
tool_map = select_tools(only:, except:).transform_keys { |name| "#{prefix}#{name}" }
tool_map.each do |tool_name, klass|
tool = klass.new(root: capsule, snapshot_cache: cache)
if capsule.roles[:governance] && tool.respond_to?(:governance=)
tool.governance = capsule.roles[:governance]
end
register_tool(capsule, tool_name, tool)
installed[tool_name] = tool
end
cache.fetch
installed
end
|
50
51
52
53
54
55
56
57
|
# File 'lib/vsm/meta.rb', line 50
def register_tool(capsule, name, tool)
key = name.to_s
capsule.children[key] = tool
context_children = capsule.bus.context[:operations_children]
if context_children.is_a?(Hash)
context_children[key] = tool
end
end
|
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/vsm/meta.rb', line 37
def select_tools(only:, except:)
map = DEFAULT_TOOL_MAP
if only && !Array(only).empty?
keys = Array(only).map(&:to_s)
map = map.select { |name, _| keys.include?(name) }
end
if except && !Array(except).empty?
rejects = Array(except).map(&:to_s)
map = map.reject { |name, _| rejects.include?(name) }
end
map
end
|