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

#initializeContext

Returns a new instance of Context.



107
108
109
110
111
# File 'lib/raif/model_manifest/dsl.rb', line 107

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.



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

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_providersObject (readonly)

Returns the value of attribute embedding_providers.



105
106
107
# File 'lib/raif/model_manifest/dsl.rb', line 105

def embedding_providers
  @embedding_providers
end

#providersObject (readonly)

Returns the value of attribute providers.



105
106
107
# File 'lib/raif/model_manifest/dsl.rb', line 105

def providers
  @providers
end

Instance Method Details

#embeddings(&block) ⇒ Object



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

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.



115
116
117
118
119
# File 'lib/raif/model_manifest/dsl.rb', line 115

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

#provider(name, &block) ⇒ Object



121
122
123
124
125
# File 'lib/raif/model_manifest/dsl.rb', line 121

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