Class: GoodJob::Setting

Inherits:
BaseRecord
  • Object
show all
Defined in:
app/models/good_job/setting.rb

Constant Summary collapse

CRON_KEYS_ENABLED =
"cron_keys_enabled"
CRON_KEYS_DISABLED =
"cron_keys_disabled"

Class Method Summary collapse

Methods inherited from BaseRecord

bind_value, migrated?, migration_pending_warning!, with_logger_silenced

Class Method Details

.cron_key_disable(key) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/good_job/setting.rb', line 35

def self.cron_key_disable(key)
  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
  disabled_setting.value << key unless disabled_setting.value.include?(key)
  disabled_setting.save!
end

.cron_key_enable(key) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/good_job/setting.rb', line 21

def self.cron_key_enable(key)
  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!

  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

.cron_key_enabled?(key, default: true) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'app/models/good_job/setting.rb', line 11

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