Class: Raif::ModelManifest::Dsl::Context

Inherits:
BasicObject
Defined in:
lib/raif/model_manifest/dsl.rb

Overview

Collects one file's declarations. A fresh instance per file keeps a manifest file from seeing (or corrupting) what another file declared.

Constant Summary collapse

Date =

A BasicObject does not inherit Object's constant table, so Date has to be reachable from here for Date.new(2026, 8, 24) in a manifest file to resolve. It is deliberately the only constant a manifest file can name unqualified.

::Date

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Context

Returns a new instance of Context.



135
136
137
138
139
# File 'lib/raif/model_manifest/dsl.rb', line 135

def initialize
  @providers = []
  @embedding_providers = []
  @source_path = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object

No respond_to_missing? counterpart: BasicObject has no respond_to? for it to answer.



163
164
165
166
# File 'lib/raif/model_manifest/dsl.rb', line 163

def method_missing(name, *_args)
  ::Kernel.raise UnknownDeclaration,
    "#{@source_path}: `#{name}` is not a manifest declaration; a manifest file may only declare `provider` and `embeddings`"
end

Instance Attribute Details

#embedding_providers ⇒ Object (readonly)

Returns the value of attribute embedding_providers.



133
134
135
# File 'lib/raif/model_manifest/dsl.rb', line 133

def embedding_providers
  @embedding_providers
end

#providers ⇒ Object (readonly)

Returns the value of attribute providers.



133
134
135
# File 'lib/raif/model_manifest/dsl.rb', line 133

def providers
  @providers
end

Instance Method Details

#embeddings(&block) ⇒ Object



155
156
157
158
159
# File 'lib/raif/model_manifest/dsl.rb', line 155

def embeddings(&block)
  builder = EmbeddingRegistryBuilder.new(source_path: @source_path)
  block.call(builder)
  @embedding_providers.concat(builder.finish)
end

#evaluate(source, source_path) ⇒ Object

Evaluating with the file's real path means an exception raised from a declaration points at the manifest line that caused it.



143
144
145
146
147
# File 'lib/raif/model_manifest/dsl.rb', line 143

def evaluate(source, source_path)
  @source_path = source_path
  instance_eval(source, source_path, 1)
  self
end

#provider(name, &block) ⇒ Object



149
150
151
152
153
# File 'lib/raif/model_manifest/dsl.rb', line 149

def provider(name, &block)
  builder = ProviderBuilder.new(name: name, source_path: @source_path)
  block.call(builder)
  @providers << builder.finish
end