Module: LittleGhost::MCP::ImmutableValue
- Defined in:
- lib/little_ghost/mcp/types.rb
Overview
:nodoc:
Class Method Summary collapse
- .array(value, field:) ⇒ Object
- .freeze_value(value) ⇒ Object
- .mapping(value, field:) ⇒ Object
- .optional_mapping(value, field:) ⇒ Object
Class Method Details
.array(value, field:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/little_ghost/mcp/types.rb', line 22 def array(value, field:) raise ProtocolError, "MCP #{field} must be an array" unless value.is_a?(Array) freeze_value(DataMap.new("items" => value).fetch("items")) rescue ArgumentError => error raise ProtocolError, "MCP #{field} is invalid: #{error.}" end |
.freeze_value(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/little_ghost/mcp/types.rb', line 30 def freeze_value(value) pending = [value] until pending.empty? current = pending.pop case current when Hash current.each do |key, child| key.freeze pending << child end when Array current.each { |child| pending << child } end current.freeze end value end |
.mapping(value, field:) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/little_ghost/mcp/types.rb', line 8 def mapping(value, field:) raise ProtocolError, "MCP #{field} must be an object" unless value.is_a?(Hash) freeze_value(DataMap.new(value)) rescue ArgumentError => error raise ProtocolError, "MCP #{field} is invalid: #{error.}" end |
.optional_mapping(value, field:) ⇒ Object
16 17 18 19 20 |
# File 'lib/little_ghost/mcp/types.rb', line 16 def optional_mapping(value, field:) return if value.nil? mapping(value, field:) end |