Class: LightGptProxy::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/light_gpt_proxy/templates/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Template

Returns a new instance of Template.



12
13
14
15
16
# File 'lib/light_gpt_proxy/templates/template.rb', line 12

def initialize(**params)
  @params = params
  validate_params!
  @attributes = self.class.optional.merge(params)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18
19
20
# File 'lib/light_gpt_proxy/templates/template.rb', line 18

def attributes
  @attributes
end

#paramsObject (readonly)

Returns the value of attribute params.



18
19
20
# File 'lib/light_gpt_proxy/templates/template.rb', line 18

def params
  @params
end

Class Method Details

.optionalObject



10
# File 'lib/light_gpt_proxy/templates/template.rb', line 10

def self.optional = {}.freeze

.requiredObject

Raises:

  • (NotImplementedError)


9
# File 'lib/light_gpt_proxy/templates/template.rb', line 9

def self.required = raise(NotImplementedError)

.templateObject

Raises:

  • (NotImplementedError)


8
# File 'lib/light_gpt_proxy/templates/template.rb', line 8

def self.template = raise(NotImplementedError)

Instance Method Details

#save(path:) ⇒ Object



20
# File 'lib/light_gpt_proxy/templates/template.rb', line 20

def save(path:) = File.write(path, to_yaml)

#to_hObject



21
# File 'lib/light_gpt_proxy/templates/template.rb', line 21

def to_h = @to_h ||= YAML.safe_load(to_yaml, permitted_classes: [Symbol])

#to_yamlObject



22
# File 'lib/light_gpt_proxy/templates/template.rb', line 22

def to_yaml = @to_yaml ||= ERB.new(self.class.template.to_yaml).result(binding)