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

#resultObject

The result attribute allows reading and setting the final outcome of a command operation.



34
35
36
# File 'lib/ollama/handlers/concern.rb', line 34

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.

Returns:

  • (Proc)

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



55
56
57
# File 'lib/ollama/handlers/concern.rb', line 55

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