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.



130
131
132
133
134
# File 'lib/raif/model_manifest/dsl.rb', line 130

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.



158
159
160
161
# File 'lib/raif/model_manifest/dsl.rb', line 158

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.



128
129
130
# File 'lib/raif/model_manifest/dsl.rb', line 128

def embedding_providers
  @embedding_providers
end

#providers ⇒ Object (readonly)

Returns the value of attribute providers.



128
129
130
# File 'lib/raif/model_manifest/dsl.rb', line 128

def providers
  @providers
end

Instance Method Details

#embeddings(&block) ⇒ Object



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

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.



138
139
140
141
142
# File 'lib/raif/model_manifest/dsl.rb', line 138

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

#provider(name, &block) ⇒ Object



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

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