Module: OllamaChat::Utils::Fetcher::HeaderExtension

Defined in:
lib/ollama_chat/utils/fetcher.rb

Overview

A module that extends IO objects with content type metadata and expiration tracking.

This module provides a way to attach MIME content type information and cache expiration details to IO objects, enabling them to carry metadata about their source and caching behavior. It is primarily used by fetcher implementations to decorate response objects with additional context for processing and caching decisions.

Examples:

Extending an IO object with header metadata

io = StringIO.new("content")
io.extend(OllamaChat::Utils::Fetcher::HeaderExtension)
io.content_type = MIME::Types['text/plain'].first
io.ex = 3600

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#content_typeString

The content_type method accesses the content type attribute of the object.

Returns:

  • (String)

    the content type of the object.



40
41
42
# File 'lib/ollama_chat/utils/fetcher.rb', line 40

def content_type
  @content_type
end

#exObject

The ex accessor is used to get or set the expiry value in seconds.



43
44
45
# File 'lib/ollama_chat/utils/fetcher.rb', line 43

def ex
  @ex
end

Class Method Details

.failedStringIO

The failed method creates a StringIO object with a text/plain content type.

This method is used to generate a failed response object that can be used when an operation does not succeed. It initializes a new StringIO object and extends it with the current class, setting its content type to text/plain.

Returns:

  • (StringIO)

    a StringIO object with text/plain content type



53
54
55
56
57
# File 'lib/ollama_chat/utils/fetcher.rb', line 53

def self.failed
  object = StringIO.new.extend(self)
  object.content_type = MIME::Types['text/plain'].first
  object
end