Class: RubyBots::Tool
- Inherits:
-
Object
- Object
- RubyBots::Tool
- Defined in:
- lib/ruby_bots/tool.rb
Overview
Base class for all RubyBots tools and bots
Direct Known Subclasses
Class Attribute Summary collapse
-
.input_validators ⇒ Object
Returns the value of attribute input_validators.
-
.output_validators ⇒ Object
Returns the value of attribute output_validators.
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, description:) ⇒ Tool
constructor
A new instance of Tool.
- #response(input) ⇒ Object
Constructor Details
#initialize(name:, description:) ⇒ Tool
Returns a new instance of Tool.
6 7 8 9 10 |
# File 'lib/ruby_bots/tool.rb', line 6 def initialize(name:, description:) @name = name @description = description @errors = [] end |
Class Attribute Details
.input_validators ⇒ Object
Returns the value of attribute input_validators.
13 14 15 |
# File 'lib/ruby_bots/tool.rb', line 13 def input_validators @input_validators end |
.output_validators ⇒ Object
Returns the value of attribute output_validators.
13 14 15 |
# File 'lib/ruby_bots/tool.rb', line 13 def output_validators @output_validators end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/ruby_bots/tool.rb', line 4 def description @description end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/ruby_bots/tool.rb', line 4 def errors @errors end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/ruby_bots/tool.rb', line 4 def name @name end |
Class Method Details
.validate_input(method) ⇒ Object
16 17 18 19 |
# File 'lib/ruby_bots/tool.rb', line 16 def self.validate_input(method) @input_validators ||= [] @input_validators << method end |
.validate_output(method) ⇒ Object
21 22 23 24 |
# File 'lib/ruby_bots/tool.rb', line 21 def self.validate_output(method) @output_validators ||= [] @output_validators << method end |
Instance Method Details
#response(input) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_bots/tool.rb', line 26 def response(input) run_input_validations(input) raise RubyBots::InvalidInputError, { errors: @errors } if @errors.any? output = run(input) run_output_validations(output) raise RubyBots::InvalidOutputError, { errors: @errors } if @errors.any? output end |