Class: OllamaChat::StateSelectors::DatabaseStateSelector
- Inherits:
-
Object
- Object
- OllamaChat::StateSelectors::DatabaseStateSelector
- Includes:
- Common
- Defined in:
- lib/ollama_chat/state_selectors.rb
Overview
A state selector that manages configurable states by reading from and writing to a chat session's attribute.
Instance Attribute Summary
Attributes included from Common
#allow_empty, #default, #name, #off, #states
Attributes included from Utils::Chooser
#current_search_state Stores the
Instance Method Summary collapse
-
#initialize(chat:, attribute:, name:, states:, default: nil, off: nil, allow_empty: false) ⇒ DatabaseStateSelector
constructor
Initializes a new DatabaseStateSelector.
-
#selected ⇒ Object
The selected reader returns the current value of the attribute from the chat session.
-
#selected=(value) ⇒ Object
The selected= method sets the attribute value in the chat session.
Methods included from Common
#allow_empty?, #choose, #off?, #on?, #show, #to_s
Methods included from Utils::Chooser
#choose_entry, #choose_with_state
Constructor Details
#initialize(chat:, attribute:, name:, states:, default: nil, off: nil, allow_empty: false) ⇒ DatabaseStateSelector
Initializes a new DatabaseStateSelector.
188 189 190 191 192 193 194 195 196 |
# File 'lib/ollama_chat/state_selectors.rb', line 188 def initialize(chat:, attribute:, name:, states:, default: nil, off: nil, allow_empty: false) @chat = chat @attribute = attribute @name = name @states = states @default = @chat.session.send(@attribute) @off = off @allow_empty = allow_empty end |
Instance Method Details
#selected ⇒ Object
The selected reader returns the current value of the attribute from the chat session.
201 202 203 |
# File 'lib/ollama_chat/state_selectors.rb', line 201 def selected @chat.session.send(@attribute) end |
#selected=(value) ⇒ Object
The selected= method sets the attribute value in the chat session.
211 212 213 214 215 216 217 218 |
# File 'lib/ollama_chat/state_selectors.rb', line 211 def selected=(value) value = value.to_s unless allow_empty? states.member?(value) or raise ArgumentError, "value has to be one of #{states.to_a * ', '}." end @chat.session.update("#@attribute": value) end |