mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Introduce Theme#get_setting (#24032)
Why this change? Currently, we do not have a method to easily retrieve a theme setting's value on the server side. Such a method can be useful in the test environment where we need to retrieve the theme's setting and use its value in assertions. What does this change do? This change introduces the `Theme#get_setting` instance method.
This commit is contained in:
committed by
GitHub
parent
c06b308895
commit
f2a90afa4c
@@ -699,6 +699,26 @@ class Theme < ActiveRecord::Base
|
||||
hash
|
||||
end
|
||||
|
||||
# Retrieves a theme setting
|
||||
#
|
||||
# @param setting_name [String, Symbol] The name of the setting to retrieve.
|
||||
#
|
||||
# @return [Object] The value of the setting that matches the provided name.
|
||||
#
|
||||
# @raise [Discourse::NotFound] If no setting is found with the provided name.
|
||||
#
|
||||
# @example
|
||||
# theme.get_setting("some_boolean") => True
|
||||
# theme.get_setting("some_string") => "hello"
|
||||
# theme.get_setting(:some_boolean) => True
|
||||
# theme.get_setting(:some_string) => "hello"
|
||||
#
|
||||
def get_setting(setting_name)
|
||||
target_setting = settings.find { |setting| setting.name == setting_name.to_sym }
|
||||
raise Discourse::NotFound unless target_setting
|
||||
target_setting.value
|
||||
end
|
||||
|
||||
def update_setting(setting_name, new_value)
|
||||
target_setting = settings.find { |setting| setting.name == setting_name }
|
||||
raise Discourse::NotFound unless target_setting
|
||||
|
||||
Reference in New Issue
Block a user