app/models/good_job/setting.rb in good_job-3.26.2 vs app/models/good_job/setting.rb in good_job-3.27.0

- old
+ new

@@ -1,30 +1,49 @@ # frozen_string_literal: true module GoodJob class Setting < BaseRecord + CRON_KEYS_ENABLED = "cron_keys_enabled" CRON_KEYS_DISABLED = "cron_keys_disabled" self.table_name = 'good_job_settings' + self.implicit_order_column = 'created_at' - def self.cron_key_enabled?(key) - cron_disabled = find_by(key: CRON_KEYS_DISABLED)&.value || [] - cron_disabled.exclude?(key.to_s) + def self.cron_key_enabled?(key, default: true) + if default + cron_disabled = find_by(key: CRON_KEYS_DISABLED)&.value || [] + cron_disabled.exclude?(key.to_s) + else + cron_enabled = find_by(key: CRON_KEYS_ENABLED)&.value || [] + cron_enabled.include?(key.to_s) + end end def self.cron_key_enable(key) - setting = GoodJob::Setting.find_by(key: CRON_KEYS_DISABLED) - return unless setting&.value&.include?(key.to_s) + enabled_setting = find_or_initialize_by(key: CRON_KEYS_ENABLED) do |record| + record.value = [] + end + enabled_setting.value << key unless enabled_setting.value.include?(key) + enabled_setting.save! - setting.value.delete(key.to_s) - setting.save! + disabled_setting = GoodJob::Setting.find_by(key: CRON_KEYS_DISABLED) + return unless disabled_setting&.value&.include?(key.to_s) + + disabled_setting.value.delete(key.to_s) + disabled_setting.save! end def self.cron_key_disable(key) - setting = find_or_initialize_by(key: CRON_KEYS_DISABLED) do |record| + enabled_setting = GoodJob::Setting.find_by(key: CRON_KEYS_ENABLED) + if enabled_setting&.value&.include?(key.to_s) + enabled_setting.value.delete(key.to_s) + enabled_setting.save! + end + + disabled_setting = find_or_initialize_by(key: CRON_KEYS_DISABLED) do |record| record.value = [] end - setting.value << key - setting.save! + disabled_setting.value << key unless disabled_setting.value.include?(key) + disabled_setting.save! end end end