Class: ActionMCP::Client::Blueprint::ResourceTemplate
- Inherits:
-
Object
- Object
- ActionMCP::Client::Blueprint::ResourceTemplate
- Defined in:
- lib/action_mcp/client/blueprint.rb
Overview
Internal Blueprint class to represent individual URI templates
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#compatible_with?(params) ⇒ Boolean
Check if this template is compatible with a set of parameters.
-
#construct(params) ⇒ String
Construct a concrete URI by substituting parameters into the template pattern.
-
#initialize(data) ⇒ ResourceTemplate
constructor
Initialize a new ResourceTemplate instance.
-
#protocol ⇒ String
Get the protocol part of the URI template.
-
#to_h ⇒ Hash
Generate a hash representation of the blueprint.
-
#variables ⇒ Array<String>
Extract variable names from the template pattern.
Constructor Details
#initialize(data) ⇒ ResourceTemplate
Initialize a new ResourceTemplate instance
98 99 100 101 102 103 104 105 |
# File 'lib/action_mcp/client/blueprint.rb', line 98 def initialize(data) @pattern = data["uriTemplate"] @name = data["name"] @description = data["description"] @mime_type = data["mimeType"] @variable_pattern = /{([^}]+)}/ @annotations = data["annotations"] || {} end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
92 93 94 |
# File 'lib/action_mcp/client/blueprint.rb', line 92 def annotations @annotations end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
92 93 94 |
# File 'lib/action_mcp/client/blueprint.rb', line 92 def description @description end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
92 93 94 |
# File 'lib/action_mcp/client/blueprint.rb', line 92 def mime_type @mime_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
92 93 94 |
# File 'lib/action_mcp/client/blueprint.rb', line 92 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
92 93 94 |
# File 'lib/action_mcp/client/blueprint.rb', line 92 def pattern @pattern end |
Instance Method Details
#compatible_with?(params) ⇒ Boolean
Check if this template is compatible with a set of parameters
143 144 145 146 |
# File 'lib/action_mcp/client/blueprint.rb', line 143 def compatible_with?(params) symbolized_params = params.transform_keys(&:to_sym) variables.all? { |var| symbolized_params.key?(var.to_sym) } end |
#construct(params) ⇒ String
Construct a concrete URI by substituting parameters into the template pattern
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/action_mcp/client/blueprint.rb', line 126 def construct(params) result = @pattern.dup variables.each do |var| raise KeyError, "Missing required parameter: #{var}" unless params.key?(var.to_sym) || params.key?(var) value = params[var.to_sym] || params[var] result.gsub!("{#{var}}", value.to_s) end result end |
#protocol ⇒ String
Get the protocol part of the URI template
117 118 119 |
# File 'lib/action_mcp/client/blueprint.rb', line 117 def protocol @pattern.split("://").first end |
#to_h ⇒ Hash
Generate a hash representation of the blueprint
151 152 153 154 155 156 157 158 159 |
# File 'lib/action_mcp/client/blueprint.rb', line 151 def to_h { "uriTemplate" => @pattern, "name" => @name, "description" => @description, "mimeType" => @mime_type, "annotations" => @annotations } end |
#variables ⇒ Array<String>
Extract variable names from the template pattern
110 111 112 |
# File 'lib/action_mcp/client/blueprint.rb', line 110 def variables @pattern.scan(@variable_pattern).flatten end |