Class: OllamaChat::Switches::CombinedSwitch

Inherits:
Object
  • Object
show all
Includes:
CheckSwitch
Defined in:
lib/ollama_chat/switches.rb

Overview

Manages a boolean state based on a dynamic proc evaluation.

The CombinedSwitch class is useful for complex conditions that depend on multiple factors or dynamic values, such as combining multiple switch states into a single effective state.

Examples:

Checking if embedding is currently performed

# When embedding_enabled is true and embedding_paused is false,
# the combined switch will return true
combined_switch.value # => true

Instance Method Summary collapse

Methods included from CheckSwitch

#off?, #show

Constructor Details

#initialize(value:, msg:) ⇒ CombinedSwitch

Initializes a new CombinedSwitch instance.

Parameters:

  • value (Proc) —

    the proc used to determine the current state. Must be invokable with no arguments. If the proc responds to arity, it must return 0 or -1 (a TypeError is raised otherwise); procs without an arity method are accepted as-is.

  • msg (Hash{Boolean => String}) —

    the message hash containing true and false keys

Raises:

  • (TypeError) —

    if value responds to arity and returns a value greater than 0 (the proc must be invokable with no args)



257
258
259
260
261
262
263
# File 'lib/ollama_chat/switches.rb', line 257

def initialize(value:, msg:)
  if arity = value.ask_and_send(:arity)
    arity <= 0 or raise TypeError, 'value Proc requires arity <= 0'
  end
  @value = value
  @msg   = msg
end

Instance Method Details

#value ⇒ Boolean

Returns the result of calling the stored proc.

Returns:

  • (Boolean) —

    the result of the dynamic evaluation



268
269
270
# File 'lib/ollama_chat/switches.rb', line 268

def value
  @value.()
end