Module: Ollama::Handlers::Concern

Extended by:
Tins::Concern, Tins::Implement
Included in:
Collector, DumpJSON, DumpYAML, Markdown, NOP, Print, Progress, Say, Single
Defined in:
lib/ollama/handlers/concern.rb

Overview

A module that defines the common interface and behavior for all response handlers used with Ollama client commands.

Handlers are responsible for processing responses from the Ollama API according to specific logic, such as printing output, collecting results, or displaying progress. This module establishes the foundational structure that all handler classes must implement to be compatible with the client’s command execution flow.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outputIO (readonly)

The output attribute reader returns the output stream used by the client.

Returns:

  • (IO)

    the output stream, typically $stdout, to which responses and messages are written



28
29
30
# File 'lib/ollama/handlers/concern.rb', line 28

def output
  @output
end

#resultOllama::Response, ... (readonly)

The result method returns the collected response data from handler operations.

This method provides access to the accumulated results after a command has been executed with a handler that collects responses, such as Collector or Single handlers.

Returns:

  • (Ollama::Response, Array<Ollama::Response>, nil)

    the result of the handler operation, which may be a single response, an array of responses, or nil depending on the handler type and the command execution



39
40
41
# File 'lib/ollama/handlers/concern.rb', line 39

def result
  @result
end

Instance Method Details

#initialize(output: $stdout) ⇒ Object

The initialize method sets up a new handler instance with the specified output destination.

Parameters:

  • output (IO) (defaults to: $stdout)

    the output stream to be used for handling responses, defaults to $stdout



20
21
22
# File 'lib/ollama/handlers/concern.rb', line 20

def initialize(output: $stdout)
  @output = output
end

#to_procProc

The to_proc method converts the handler instance into a proc object.

This method returns a lambda that takes a response parameter and calls the handler’s call method with that response, enabling the handler to be used in contexts where a proc is expected.

processing

Returns:

  • (Proc)

    a proc that wraps the handler’s call method for response



61
62
63
# File 'lib/ollama/handlers/concern.rb', line 61

def to_proc
  -> response { call(response) }
end