Class: GoodJob::Setting
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/models/good_job/setting.rb', line 36
def self.cron_key_disable(key)
enabled_setting = GoodJob::Setting.find_by(key: CRON_KEYS_ENABLED)
key_string = key.to_s
if enabled_setting&.value&.include?(key_string)
enabled_setting.value.delete(key_string)
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_string)
disabled_setting.save!
end
|
.cron_key_enable(key) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/models/good_job/setting.rb', line 21
def self.cron_key_enable(key)
key_string = 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_string)
enabled_setting.save!
disabled_setting = GoodJob::Setting.find_by(key: CRON_KEYS_DISABLED)
return unless disabled_setting&.value&.include?(key_string)
disabled_setting.value.delete(key_string)
disabled_setting.save!
end
|
.cron_key_enabled?(key, default: true) ⇒ 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
|