Module: OmnifocusMcp::Tools::Params::McpBoundary
- Defined in:
- lib/omnifocus_mcp/tools/params/mcp_boundary.rb
Overview
Builds Data.define param structs from MCP wire args or snake_case Hashes.
Class Method Summary collapse
- .build(klass, args, deep: false) ⇒ Object
-
.coerce(klass, value) ⇒ Object
Accept a param struct or a snake_case Hash (e.g. specs, script helpers).
- .from_hash(klass, hash) ⇒ Object
- .from_snake_hash(klass, snake) ⇒ Object
Class Method Details
.build(klass, args, deep: false) ⇒ Object
14 15 16 17 |
# File 'lib/omnifocus_mcp/tools/params/mcp_boundary.rb', line 14 def build(klass, args, deep: false) snake = Definitions::KeyNormalizer.snake_keys(args, deep: deep) from_snake_hash(klass, snake) end |
.coerce(klass, value) ⇒ Object
Accept a param struct or a snake_case Hash (e.g. specs, script helpers).
30 31 32 33 34 35 36 |
# File 'lib/omnifocus_mcp/tools/params/mcp_boundary.rb', line 30 def coerce(klass, value) case value when klass then value when Hash then klass.from_hash(value) else raise ArgumentError, "expected #{klass.name}, got #{value.class}" end end |
.from_hash(klass, hash) ⇒ Object
21 22 23 |
# File 'lib/omnifocus_mcp/tools/params/mcp_boundary.rb', line 21 def from_hash(klass, hash) from_snake_hash(klass, hash || {}) end |
.from_snake_hash(klass, snake) ⇒ Object
25 26 27 |
# File 'lib/omnifocus_mcp/tools/params/mcp_boundary.rb', line 25 def from_snake_hash(klass, snake) klass.new(**klass.members.to_h { |member| [member, snake[member]] }) end |