Module: Rach::Function
- Defined in:
- lib/rach/function.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.find_by_name(name) ⇒ Object
Add function lookup method.
-
.functions ⇒ Object
Add function registry.
- .included(base) ⇒ Object
Instance Method Summary collapse
- #execute(**args) ⇒ Object
- #function_description ⇒ Object
- #function_name ⇒ Object
-
#schema ⇒ Object
Instance methods that must be implemented by including class.
- #validate_arguments!(arguments) ⇒ Object
Class Method Details
permalink .find_by_name(name) ⇒ Object
Add function lookup method
18 19 20 |
# File 'lib/rach/function.rb', line 18 def self.find_by_name(name) functions.find { |func| func.new.function_name == name } end |
permalink .functions ⇒ Object
Add function registry
13 14 15 |
# File 'lib/rach/function.rb', line 13 def self.functions @functions ||= [] end |
permalink .included(base) ⇒ Object
[View source]
3 4 5 6 7 8 9 10 |
# File 'lib/rach/function.rb', line 3 def self.included(base) require 'json/schema_builder' base.include JSON::SchemaBuilder base.extend ClassMethods # Register the function when included functions << base end |
Instance Method Details
permalink #execute(**args) ⇒ Object
72 73 74 |
# File 'lib/rach/function.rb', line 72 def execute(**args) raise NotImplementedError, "#{self.class} must implement #execute" end |
permalink #function_description ⇒ Object
80 81 82 |
# File 'lib/rach/function.rb', line 80 def function_description raise NotImplementedError, "#{self.class} must implement #function_description" end |
permalink #function_name ⇒ Object
76 77 78 |
# File 'lib/rach/function.rb', line 76 def function_name raise NotImplementedError, "#{self.class} must implement #function_name" end |
permalink #schema ⇒ Object
Instance methods that must be implemented by including class
68 69 70 |
# File 'lib/rach/function.rb', line 68 def schema raise NotImplementedError, "#{self.class} must implement #schema" end |
permalink #validate_arguments!(arguments) ⇒ Object
[View source]
84 85 86 87 88 |
# File 'lib/rach/function.rb', line 84 def validate_arguments!(arguments) unless schema.validate(arguments) raise ArgumentError, "Invalid arguments for function #{function_name}" end end |