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

Class Method Details

.build(klass, args, deep: false) ⇒ Object

Parameters:

  • klass (Data)

    struct class whose members list snake_case fields

  • args (Hash)

    raw MCP arguments (camelCase Symbol keys)

  • deep (Boolean) (defaults to: false)

    recurse into nested Hashes and Arrays of Hashes



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

Parameters:

  • klass (Data)
  • hash (Hash)

    snake_case Symbol keys (e.g. from tests or resources)



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