Skip to content
Kward Search API index

Class: Kward::PluginCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/plugins/actions.rb

Overview

Registered slash command with optional typed argument parsing.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


409
410
411
# File 'lib/kward/plugins/actions.rb', line 409

def typed?
  !@arguments.nil?
end