module VetoStore
Constants
- AUDIT_KEY
- MAX_AUDIT_ENTRIES
- PENDING_KEY
- PLUGIN
Public Instance Methods
Source
# File lib/veto_store.rb, line 94 def append_audit(network:, channel:, event:, data:, store: RabbotDb) entries = Array( store.get_plugin_json(plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, default: []) ) entries << { "at" => store.iso_time(Time.now), "event" => event.to_s, "data" => data } store.set_plugin_json( plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, value: entries.last(MAX_AUDIT_ENTRIES) ) end
Source
# File lib/veto_store.rb, line 112 def audit_log(network:, channel:, store: RabbotDb) Array( store.get_plugin_json(plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, default: []) ) end
Source
# File lib/veto_store.rb, line 75 def clear_pending(network:, channel:, store: RabbotDb) store.set_plugin_json(plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel, value: {}) end
Source
# File lib/veto_store.rb, line 34 def load_pending(network:, channel:, store: RabbotDb) payload = store.get_plugin_json(plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel, default: nil) return nil unless payload.is_a?(Hash) && !payload.empty? staged_at = store.parse_time(payload["staged_at"]) || Time.now { id: payload["id"].to_s, experiment: payload["experiment"].to_s, idea: payload["experiment"].to_s, source: payload["source"].to_s, vetoed: payload["vetoed"] == true, vetoed_by: payload["vetoed_by"].to_s, staged_at: staged_at, veto_window_sec: payload["veto_window_sec"].to_i } end
Source
# File lib/veto_store.rb, line 51 def mark_vetoed(network:, channel:, vetor:, store: RabbotDb) pending = load_pending(network: network, channel: channel, store: store) return nil unless pending pending[:vetoed] = true pending[:vetoed_by] = vetor.to_s save_pending( network: network, channel: channel, entry: pending, staged_at: pending[:staged_at], veto_window_sec: pending[:veto_window_sec], store: store ) append_audit( network: network, channel: channel, event: "vetoed", data: { "id" => pending[:id], "vetor" => vetor.to_s }, store: store ) pending end
Source
# File lib/veto_store.rb, line 79 def record_outcome(network:, channel:, entry:, outcome:, store: RabbotDb) append_audit( network: network, channel: channel, event: outcome.to_s, data: { "id" => entry[:id].to_s, "experiment" => (entry[:experiment] || entry[:idea]).to_s, "source" => entry[:source].to_s }, store: store ) clear_pending(network: network, channel: channel, store: store) end
Source
# File lib/veto_store.rb, line 13 def save_pending(network:, channel:, entry:, staged_at:, veto_window_sec:, store: RabbotDb) payload = { "id" => entry[:id].to_s, "experiment" => (entry[:experiment] || entry[:idea]).to_s, "source" => entry[:source].to_s, "vetoed" => entry[:vetoed] == true, "vetoed_by" => entry[:vetoed_by].to_s, "staged_at" => store.iso_time(staged_at), "veto_window_sec" => veto_window_sec.to_i } payload.delete("vetoed_by") if payload["vetoed_by"].empty? store.set_plugin_json(plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel, value: payload) append_audit( network: network, channel: channel, event: "staged", data: { "id" => payload["id"], "source" => payload["source"], "experiment" => payload["experiment"] }, store: store ) end