Skip to content
Kward Search API index

Class: Kward::PluginAction

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

Overview

Registered namespaced action exposed to trusted RPC clients.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, plugin_id:, description:, schema:, path:, handler:) ⇒ PluginAction

Returns a new instance of PluginAction.



431
432
433
434
435
436
437
438
439
440
441
# File 'lib/kward/plugins/actions.rb', line 431

def initialize(name:, plugin_id:, description:, schema:, path:, handler:)
  @name = name
  @plugin_id = plugin_id
  @id = "#{plugin_id}/#{name}"
  @description = description
  @path = path
  @handler = handler
  @arguments = PluginArguments.new(label: "Plugin action #{id}", schema: schema)
  @schema = @arguments.schema
  freeze
end

Instance Attribute Details

#description ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def description
  @description
end

#handler ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def handler
  @handler
end

#id ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def id
  @id
end

#name ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def name
  @name
end

#path ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def path
  @path
end

#plugin_id ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def plugin_id
  @plugin_id
end

#schema ⇒ Object (readonly)



429
430
431
# File 'lib/kward/plugins/actions.rb', line 429

def schema
  @schema
end

Instance Method Details

#normalize_result(value) ⇒ Object



449
450
451
# File 'lib/kward/plugins/actions.rb', line 449

def normalize_result(value)
  PluginResult.wrap(value)
end

#parse_arguments(value) ⇒ Object

Raises:

  • (ArgumentError)


443
444
445
446
447
# File 'lib/kward/plugins/actions.rb', line 443

def parse_arguments(value)
  raise ArgumentError, "Plugin action #{id} arguments must be an object" unless value.is_a?(Hash)

  @arguments.parse(value)
end