Class: OllamaChat::Switches::DatabaseSwitch
- Inherits:
-
Object
- Object
- OllamaChat::Switches::DatabaseSwitch
- Includes:
- CheckSwitch
- Defined in:
- lib/ollama_chat/switches.rb
Overview
Manages boolean configuration states that are persisted in the database.
This class acts as a wrapper around a database attribute, allowing for toggling and setting of boolean values while ensuring that changes are immediately saved to the associated session.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(chat:, msg:, attribute:) ⇒ DatabaseSwitch
constructor
Initializes a new DatabaseSwitch instance.
-
#set(value, show: false, output: STDOUT) ⇒ String, ...
Updates the session attribute with the given value and optionally displays it.
-
#toggle(show: true) ⇒ String, ...
Toggles the value of a session attribute and optionally displays the new state.
-
#value ⇒ Boolean
Returns the current value of the attribute from the session.
Methods included from CheckSwitch
Constructor Details
#initialize(chat:, msg:, attribute:) ⇒ DatabaseSwitch
Initializes a new DatabaseSwitch instance.
108 109 110 111 112 |
# File 'lib/ollama_chat/switches.rb', line 108 def initialize(chat:, msg:, attribute:) @chat = chat @attribute = attribute @msg = msg end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
123 124 125 |
# File 'lib/ollama_chat/switches.rb', line 123 def attribute @attribute end |
Instance Method Details
#set(value, show: false, output: STDOUT) ⇒ String, ...
Updates the session attribute with the given value and optionally displays it.
131 132 133 134 |
# File 'lib/ollama_chat/switches.rb', line 131 def set(value, show: false, output: STDOUT) @chat.session.update("#{attribute}": !!value) show && self.show(output:) end |
#toggle(show: true) ⇒ String, ...
Toggles the value of a session attribute and optionally displays the new state.
140 141 142 143 |
# File 'lib/ollama_chat/switches.rb', line 140 def toggle(show: true) @chat.session.update("#{attribute}": !value) show && self.show end |
#value ⇒ Boolean
Returns the current value of the attribute from the session.
117 118 119 |
# File 'lib/ollama_chat/switches.rb', line 117 def value @chat.session.send(@attribute) end |