Class: MetadataContext
- Inherits:
-
Object
- Object
- MetadataContext
- Defined in:
- lib/mcp/tool.rb
Overview
Context object for managing nested metadata collection
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
-
.current ⇒ Object
Class method to set/get current context for thread-safe access.
- .with_context(context) ⇒ Object
Instance Method Summary collapse
- #current_path ⇒ Object
-
#initialize ⇒ MetadataContext
constructor
A new instance of MetadataContext.
- #store(property_name, meta_key, value) ⇒ Object
- #with_nested(parent_property) ⇒ Object
Constructor Details
#initialize ⇒ MetadataContext
Returns a new instance of MetadataContext.
107 108 109 110 |
# File 'lib/mcp/tool.rb', line 107 def initialize @metadata = {} @nesting_stack = [] end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
112 113 114 |
# File 'lib/mcp/tool.rb', line 112 def @metadata end |
Class Method Details
.current ⇒ Object
Class method to set/get current context for thread-safe access
134 135 136 |
# File 'lib/mcp/tool.rb', line 134 def self.current Thread.current[:metadata_context] end |
.with_context(context) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/mcp/tool.rb', line 138 def self.with_context(context) old_context = Thread.current[:metadata_context] Thread.current[:metadata_context] = context yield ensure Thread.current[:metadata_context] = old_context end |
Instance Method Details
#current_path ⇒ Object
129 130 131 |
# File 'lib/mcp/tool.rb', line 129 def current_path @nesting_stack.dup end |
#store(property_name, meta_key, value) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/mcp/tool.rb', line 114 def store(property_name, , value) path = current_path + [property_name.to_s] full_path = path.join('.') @metadata[full_path] ||= {} @metadata[full_path][] = value end |
#with_nested(parent_property) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/mcp/tool.rb', line 122 def with_nested(parent_property) @nesting_stack.push(parent_property.to_s) yield ensure @nesting_stack.pop end |