Class: OllamaChat::LinksSet
- Inherits:
-
Object
- Object
- OllamaChat::LinksSet
- Includes:
- Enumerable
- Defined in:
- lib/ollama_chat/links_set.rb
Overview
A collection of links associated with a chat session, providing automatic synchronization to the session's persistent storage.
This class acts as a wrapper around a Set, ensuring that any mutations trigger a sync operation to save the current state to the database.
Instance Method Summary collapse
-
#add(x) ⇒ OllamaChat::LinksSet
Adds a link to the set and synchronizes it with the session.
-
#clear ⇒ OllamaChat::LinksSet
Removes all links from the set and synchronizes it with the session.
-
#delete(x) ⇒ String?
Removes a specific link from the set and synchronizes it with the session.
-
#each {|String| ... } ⇒ OllamaChat::LinksSet
Iterates over the links in the set.
-
#empty? ⇒ Boolean
Checks if the set of elements is empty.
-
#initialize(chat) ⇒ LinksSet
constructor
Initializes a new LinksSet instance and loads existing links from the session.
-
#size ⇒ Integer
Returns the number of elements in the set.
-
#sync ⇒ OllamaChat::LinksSet
Synchronizes the current in-memory set of links with the chat session.
Constructor Details
#initialize(chat) ⇒ LinksSet
Initializes a new LinksSet instance and loads existing links from the session.
13 14 15 16 |
# File 'lib/ollama_chat/links_set.rb', line 13 def initialize(chat) @chat = chat @set = Set.new(@chat.load_links_from_session) end |
Instance Method Details
#add(x) ⇒ OllamaChat::LinksSet
Adds a link to the set and synchronizes it with the session.
22 23 24 25 |
# File 'lib/ollama_chat/links_set.rb', line 22 def add(x) @set.add(x) sync end |
#clear ⇒ OllamaChat::LinksSet
Removes all links from the set and synchronizes it with the session.
30 31 32 33 |
# File 'lib/ollama_chat/links_set.rb', line 30 def clear @set.clear sync end |
#delete(x) ⇒ String?
Removes a specific link from the set and synchronizes it with the session.
39 40 41 |
# File 'lib/ollama_chat/links_set.rb', line 39 def delete(x) @set.delete(x).tap { sync } end |
#each {|String| ... } ⇒ OllamaChat::LinksSet
Iterates over the links in the set.
68 69 70 71 |
# File 'lib/ollama_chat/links_set.rb', line 68 def each(&block) @set.each(&block) self end |
#empty? ⇒ Boolean
Checks if the set of elements is empty.
54 55 56 |
# File 'lib/ollama_chat/links_set.rb', line 54 def empty? @set.empty? end |
#size ⇒ Integer
Returns the number of elements in the set.
60 61 62 |
# File 'lib/ollama_chat/links_set.rb', line 60 def size @set.size end |
#sync ⇒ OllamaChat::LinksSet
Synchronizes the current in-memory set of links with the chat session.
46 47 48 49 |
# File 'lib/ollama_chat/links_set.rb', line 46 def sync @chat.store_links_in_session(@set) self end |