Class: Kward::PluginCommand
- Inherits:
-
Object
- Object
- Kward::PluginCommand
- Defined in:
- lib/kward/plugins/actions.rb
Overview
Registered slash command with optional typed argument parsing.
Instance Attribute Summary collapse
- #argument_hint ⇒ Object readonly
- #description ⇒ Object readonly
- #handler ⇒ Object readonly
- #name ⇒ Object readonly
- #path ⇒ Object readonly
- #plugin_id ⇒ Object readonly
- #positionals ⇒ Object readonly
- #schema ⇒ Object readonly
Instance Method Summary collapse
- #entry ⇒ Object
-
#initialize(name:, description: "", argument_hint: "", schema: nil, positionals: [], plugin_id: nil, path: nil, handler: nil) ⇒ PluginCommand
constructor
A new instance of PluginCommand.
- #normalize_result(value) ⇒ Object
- #parse_arguments(value) ⇒ Object
- #typed? ⇒ Boolean
Constructor Details
#initialize(name:, description: "", argument_hint: "", schema: nil, positionals: [], plugin_id: nil, path: nil, handler: nil) ⇒ PluginCommand
Returns a new instance of PluginCommand.
396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/kward/plugins/actions.rb', line 396 def initialize(name:, description: "", argument_hint: "", schema: nil, positionals: [], plugin_id: nil, path: nil, handler: nil) @name = name @description = description @argument_hint = argument_hint @plugin_id = plugin_id @path = path @handler = handler @arguments = schema && PluginArguments.new(label: "Plugin command /#{name}", schema: schema, positionals: positionals) @schema = @arguments&.schema @positionals = @arguments&.positionals || [].freeze freeze end |
Instance Attribute Details
#argument_hint ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def argument_hint @argument_hint end |
#description ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def description @description end |
#handler ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def handler @handler end |
#name ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def name @name end |
#path ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def path @path end |
#plugin_id ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def plugin_id @plugin_id end |
#positionals ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def positionals @positionals end |
#schema ⇒ Object (readonly)
393 394 395 |
# File 'lib/kward/plugins/actions.rb', line 393 def schema @schema end |
Instance Method Details
#entry ⇒ Object
421 422 423 |
# File 'lib/kward/plugins/actions.rb', line 421 def entry { name: name, description: description, argument_hint: argument_hint } end |
#normalize_result(value) ⇒ Object
417 418 419 |
# File 'lib/kward/plugins/actions.rb', line 417 def normalize_result(value) typed? ? PluginResult.wrap(value) : value end |
#parse_arguments(value) ⇒ Object
413 414 415 |
# File 'lib/kward/plugins/actions.rb', line 413 def parse_arguments(value) typed? ? @arguments.parse(value) : value.to_s end |
#typed? ⇒ Boolean
409 410 411 |
# File 'lib/kward/plugins/actions.rb', line 409 def typed? !@arguments.nil? end |