Module: Rach::Function

Defined in:
lib/rach/function.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object

Add function lookup method

[View source]

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

.functionsObject

Add function registry

[View source]

13
14
15
# File 'lib/rach/function.rb', line 13

def self.functions
  @functions ||= []
end

.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

#execute(**args) ⇒ Object

Raises:

  • (NotImplementedError)
[View source]

72
73
74
# File 'lib/rach/function.rb', line 72

def execute(**args)
  raise NotImplementedError, "#{self.class} must implement #execute"
end

#function_descriptionObject

Raises:

  • (NotImplementedError)
[View source]

80
81
82
# File 'lib/rach/function.rb', line 80

def function_description
  raise NotImplementedError, "#{self.class} must implement #function_description"
end

#function_nameObject

Raises:

  • (NotImplementedError)
[View source]

76
77
78
# File 'lib/rach/function.rb', line 76

def function_name
  raise NotImplementedError, "#{self.class} must implement #function_name"
end

#schemaObject

Instance methods that must be implemented by including class

Raises:

  • (NotImplementedError)
[View source]

68
69
70
# File 'lib/rach/function.rb', line 68

def schema
  raise NotImplementedError, "#{self.class} must implement #schema"
end

#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