module PaintStore
PaintStore — persist IRC colour overrides per channel in RabbotDb. Public: list, save_override!, remove_for_plugin!, remove_for_line! Depends: RabbotDb Tests: test/lib/paint_store_test.rb
Constants
- KEY
- PLUGIN
Public Instance Methods
Source
# File lib/paint_store.rb, line 16 def list(network:, channel:, plugin:, store: RabbotDb) load_all(network: network, channel: channel, store: store).select do |entry| entry[:plugin].to_s == plugin.to_s end end
Source
# File lib/paint_store.rb, line 56 def load_all(network:, channel:, store: RabbotDb) raw = store.get_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, default: [] ) Array(raw).map { |entry| symbolize_override(entry) } end
Source
# File lib/paint_store.rb, line 67 def normalize_override(override) { plugin: override[:plugin].to_s, line: override[:line].to_i, plain_start: override[:plain_start].to_i, plain_end: override[:plain_end].to_i, fg: override[:fg].to_i, bg: override[:bg]&.to_i, snippet: override[:snippet] } end
Source
# File lib/paint_store.rb, line 93 def persist!(network:, channel:, overrides:, store: RabbotDb) store.set_plugin_json( plugin: PLUGIN, key: KEY, value: overrides, network: network, channel: channel ) end
Source
# File lib/paint_store.rb, line 48 def remove_for_line!(network:, channel:, plugin:, line:, store: RabbotDb) overrides = load_all(network: network, channel: channel, store: store) overrides.reject! do |entry| entry[:plugin].to_s == plugin.to_s && entry[:line].to_i == line.to_i end persist!(network: network, channel: channel, overrides: overrides, store: store) end
Source
# File lib/paint_store.rb, line 42 def remove_for_plugin!(network:, channel:, plugin:, store: RabbotDb) overrides = load_all(network: network, channel: channel, store: store) overrides.reject! { |entry| entry[:plugin].to_s == plugin.to_s } persist!(network: network, channel: channel, overrides: overrides, store: store) end
Source
# File lib/paint_store.rb, line 22 def save_override!(network:, channel:, override:, store: RabbotDb) overrides = load_all(network: network, channel: channel, store: store) normalized = normalize_override(override) overrides.reject! do |entry| entry[:plugin] == normalized[:plugin] && entry[:line] == normalized[:line] && entry[:plain_start] == normalized[:plain_start] && entry[:plain_end] == normalized[:plain_end] end overrides << normalized store.set_plugin_json( plugin: PLUGIN, key: KEY, value: overrides, network: network, channel: channel ) normalized end
Source
# File lib/paint_store.rb, line 80 def symbolize_override(entry) { plugin: entry["plugin"] || entry[:plugin], line: (entry["line"] || entry[:line]).to_i, plain_start: (entry["plain_start"] || entry[:plain_start]).to_i, plain_end: (entry["plain_end"] || entry[:plain_end]).to_i, fg: (entry["fg"] || entry[:fg]).to_i, bg: entry.key?("bg") || entry.key?(:bg) ? (entry["bg"] || entry[:bg])&.to_i : nil, snippet: entry["snippet"] || entry[:snippet] } end