Class: Kreator::PluginToolAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/kreator/plugin_tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin:, instance:) ⇒ PluginToolAdapter

Returns a new instance of PluginToolAdapter.



30
31
32
33
# File 'lib/kreator/plugin_tool.rb', line 30

def initialize(plugin:, instance:)
  @plugin = plugin
  @instance = instance
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



28
29
30
# File 'lib/kreator/plugin_tool.rb', line 28

def instance
  @instance
end

#pluginObject (readonly)

Returns the value of attribute plugin.



28
29
30
# File 'lib/kreator/plugin_tool.rb', line 28

def plugin
  @plugin
end

Instance Method Details

#call(args:, context:, signal:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/kreator/plugin_tool.rb', line 51

def call(args:, context:, signal:)
  context.approve_plugin_tool!(
    plugin: plugin.name,
    tool: name,
    description: description,
    args: args
  )
  result = instance.call(args: args, context: context, signal: signal)
  annotate_result(result)
end

#descriptionObject



43
44
45
# File 'lib/kreator/plugin_tool.rb', line 43

def description
  instance.class.description
end

#nameObject



35
36
37
# File 'lib/kreator/plugin_tool.rb', line 35

def name
  "#{plugin.name}.#{tool_name}"
end

#schemaObject



47
48
49
# File 'lib/kreator/plugin_tool.rb', line 47

def schema
  instance.class.schema
end

#to_hObject



62
63
64
65
66
67
68
69
70
# File 'lib/kreator/plugin_tool.rb', line 62

def to_h
  {
    "plugin" => plugin.name,
    "name" => name,
    "tool_name" => tool_name,
    "description" => description,
    "schema" => schema
  }
end

#tool_nameObject



39
40
41
# File 'lib/kreator/plugin_tool.rb', line 39

def tool_name
  instance.class.tool_name
end