Class: ActionMCP::Types::HashType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- ActionMCP::Types::HashType
- Defined in:
- lib/action_mcp/types/hash_type.rb
Overview
Custom ActiveModel type for JSON Schema “object” properties. Preserves Hash values without coercion.
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_mcp/types/hash_type.rb', line 12 def cast(value) case value when Hash then value when String begin parsed = JSON.parse(value) parsed.is_a?(Hash) ? parsed : nil rescue JSON::ParserError nil end end end |
#deserialize(value) ⇒ Object
29 30 31 |
# File 'lib/action_mcp/types/hash_type.rb', line 29 def deserialize(value) cast(value) end |
#serialize(value) ⇒ Object
25 26 27 |
# File 'lib/action_mcp/types/hash_type.rb', line 25 def serialize(value) cast(value) end |
#type ⇒ Object
8 9 10 |
# File 'lib/action_mcp/types/hash_type.rb', line 8 def type :hash end |