Class: Truffle::Tool::Builder
- Inherits:
-
Object
- Object
- Truffle::Tool::Builder
- Defined in:
- lib/truffle/tool.rb
Overview
Collects param declarations and the run block into a JSON Schema + handler.
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #param(name, type, description = nil, required: false, **extra) ⇒ Object
- #run(&block) ⇒ Object
- #schema ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
60 61 62 63 64 |
# File 'lib/truffle/tool.rb', line 60 def initialize @properties = {} @required = [] @handler = ->(**) { "" } end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
58 59 60 |
# File 'lib/truffle/tool.rb', line 58 def handler @handler end |
Instance Method Details
#param(name, type, description = nil, required: false, **extra) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/truffle/tool.rb', line 66 def param(name, type, description = nil, required: false, **extra) spec = { type: type.to_s } spec[:description] = description if description spec.merge!(extra) @properties[name.to_s] = spec @required << name.to_s if required self end |
#run(&block) ⇒ Object
75 76 77 78 79 |
# File 'lib/truffle/tool.rb', line 75 def run(&block) raise ArgumentError, "run requires a block" unless block @handler = block end |
#schema ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/truffle/tool.rb', line 81 def schema { type: "object", properties: @properties, required: @required } end |