Class: Textus::Contract::Spec
- Inherits:
-
Data
- Object
- Data
- Textus::Contract::Spec
- Defined in:
- lib/textus/contract.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#around ⇒ Object
readonly
Returns the value of attribute around.
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
-
#cli_stdin ⇒ Object
readonly
Returns the value of attribute cli_stdin.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#surfaces ⇒ Object
readonly
Returns the value of attribute surfaces.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
Instance Method Summary collapse
- #cli? ⇒ Boolean
- #cli_group ⇒ Object
- #cli_leaf ⇒ Object
-
#cli_path ⇒ Object
Operator-facing command path.
- #cli_words ⇒ Object
-
#input_schema ⇒ Object
JSON-Schema object for MCP tools/list inputSchema.
- #mcp? ⇒ Boolean
- #required_args ⇒ Object
-
#view(surface = :default) ⇒ Object
The output shaper for a surface; falls back to the default view.
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def args @args end |
#around ⇒ Object (readonly)
Returns the value of attribute around
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def around @around end |
#cli ⇒ Object (readonly)
Returns the value of attribute cli
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def cli @cli end |
#cli_stdin ⇒ Object (readonly)
Returns the value of attribute cli_stdin
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def cli_stdin @cli_stdin end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def summary @summary end |
#surfaces ⇒ Object (readonly)
Returns the value of attribute surfaces
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def surfaces @surfaces end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def verb @verb end |
#views ⇒ Object (readonly)
Returns the value of attribute views
36 37 38 |
# File 'lib/textus/contract.rb', line 36 def views @views end |
Instance Method Details
#cli? ⇒ Boolean
38 |
# File 'lib/textus/contract.rb', line 38 def cli? = surfaces.include?(:cli) |
#cli_group ⇒ Object
49 |
# File 'lib/textus/contract.rb', line 49 def cli_group = cli_words.size > 1 ? cli_words.first : nil |
#cli_leaf ⇒ Object
50 |
# File 'lib/textus/contract.rb', line 50 def cli_leaf = cli_words.last |
#cli_path ⇒ Object
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_words ⇒ Object
48 |
# File 'lib/textus/contract.rb', line 48 def cli_words = cli_path.split |
#input_schema ⇒ Object
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
37 |
# File 'lib/textus/contract.rb', line 37 def mcp? = surfaces.include?(:mcp) |
#required_args ⇒ Object
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) |