Class: Textus::Contract::Spec

Inherits:
Data
  • Object
show all
Defined in:
lib/textus/contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



36
37
38
# File 'lib/textus/contract.rb', line 36

def args
  @args
end

#aroundObject (readonly)

Returns the value of attribute around

Returns:

  • (Object)

    the current value of around



36
37
38
# File 'lib/textus/contract.rb', line 36

def around
  @around
end

#cliObject (readonly)

Returns the value of attribute cli

Returns:

  • (Object)

    the current value of cli



36
37
38
# File 'lib/textus/contract.rb', line 36

def cli
  @cli
end

#cli_stdinObject (readonly)

Returns the value of attribute cli_stdin

Returns:

  • (Object)

    the current value of cli_stdin



36
37
38
# File 'lib/textus/contract.rb', line 36

def cli_stdin
  @cli_stdin
end

#summaryObject (readonly)

Returns the value of attribute summary

Returns:

  • (Object)

    the current value of summary



36
37
38
# File 'lib/textus/contract.rb', line 36

def summary
  @summary
end

#surfacesObject (readonly)

Returns the value of attribute surfaces

Returns:

  • (Object)

    the current value of surfaces



36
37
38
# File 'lib/textus/contract.rb', line 36

def surfaces
  @surfaces
end

#verbObject (readonly)

Returns the value of attribute verb

Returns:

  • (Object)

    the current value of verb



36
37
38
# File 'lib/textus/contract.rb', line 36

def verb
  @verb
end

#viewsObject (readonly)

Returns the value of attribute views

Returns:

  • (Object)

    the current value of views



36
37
38
# File 'lib/textus/contract.rb', line 36

def views
  @views
end

Instance Method Details

#cli?Boolean

Returns:

  • (Boolean)


38
# File 'lib/textus/contract.rb', line 38

def cli? = surfaces.include?(:cli)

#cli_groupObject



49
# File 'lib/textus/contract.rb', line 49

def cli_group = cli_words.size > 1 ? cli_words.first : nil

#cli_leafObject



50
# File 'lib/textus/contract.rb', line 50

def cli_leaf  = cli_words.last

#cli_pathObject

Operator-facing command path. Defaults to the verb token; grouped verbs declare e.g. ‘cli “schema show”`.



47
# File 'lib/textus/contract.rb', line 47

def cli_path = cli || verb.to_s

#cli_wordsObject



48
# File 'lib/textus/contract.rb', line 48

def cli_words = cli_path.split

#input_schemaObject

JSON-Schema object for MCP tools/list inputSchema. Outer keys (:type, :properties, :required) are symbols; inner property keys are strings — matches the MCP/JSON wire shape expected by clients.



57
58
59
60
61
62
63
64
# File 'lib/textus/contract.rb', line 57

def input_schema
  props = args.to_h do |a|
    h = { "type" => Contract.json_type(a.type) }
    h["description"] = a.description if a.description
    [a.wire.to_s, h]
  end
  { type: "object", properties: props, required: required_args.map { |a| a.wire.to_s } }
end

#mcp?Boolean

Returns:

  • (Boolean)


37
# File 'lib/textus/contract.rb', line 37

def mcp? = surfaces.include?(:mcp)

#required_argsObject



52
# File 'lib/textus/contract.rb', line 52

def required_args = args.select(&:required)

#view(surface = :default) ⇒ Object

The output shaper for a surface; falls back to the default view. Every view is invoked uniformly as ‘view.call(result, inputs)` — a view that declares one parameter ignores `inputs` (procs tolerate extra args).



43
# File 'lib/textus/contract.rb', line 43

def view(surface = :default) = views[surface] || views.fetch(:default)