Class: ErrorRadar::Setting
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ErrorRadar::Setting
- Defined in:
- app/models/error_radar/setting.rb
Overview
Key-value store for UI-configurable settings (e.g. ChatWork credentials). Values are JSON-encoded so arrays/booleans survive the round-trip.
Constant Summary collapse
- CHATWORK_KEYS =
%w[ chatwork_api_token chatwork_room_id chatwork_notify_sources ].freeze
Class Method Summary collapse
Class Method Details
.chatwork_settings ⇒ Object
30 31 32 33 34 |
# File 'app/models/error_radar/setting.rb', line 30 def self.chatwork_settings CHATWORK_KEYS.each_with_object({}) do |key, hash| hash[key] = get(key) end end |
.get(key) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/models/error_radar/setting.rb', line 15 def self.get(key) row = find_by(key: key.to_s) return nil if row.nil? || row.value.nil? JSON.parse(row.value) rescue JSON::ParserError row.value end |
.set(key, value) ⇒ Object
24 25 26 27 28 |
# File 'app/models/error_radar/setting.rb', line 24 def self.set(key, value) row = find_or_initialize_by(key: key.to_s) row.value = value.nil? ? nil : value.to_json row.save! end |