handles_setting.rb 678 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Service::Concerns::HandlesSetting
  3. extend ActiveSupport::Concern
  4. class SettingError < StandardError; end
  5. included do
  6. def setting_enabled?(name)
  7. Setting.get(name)
  8. end
  9. def setting_disabled?(name)
  10. !setting_enabled?(name)
  11. end
  12. def setting_enabled!(name)
  13. raise SettingError, __('This setting is not enabled.') if setting_disabled?(name)
  14. end
  15. def setting_disabled!(name)
  16. raise SettingError, __('This setting is not disabled.') if setting_enabled?(name)
  17. end
  18. def setting_get(name)
  19. Setting.find_by(name: name)
  20. end
  21. end
  22. end