DEV: Centralise logic for validating a theme setting value (#25764)

Why this change?

The logic for validating a theme setting's value and default value was
not consistent as each part of the code would implement its own logic.
This is not ideal as the default value may be validated differently than
when we are setting a new value. Therefore, this commit seeks to
refactor all the validation logic for a theme setting's value into a
single service class.

What does this change do?

Introduce the `ThemeSettingsValidator` service class which holds all the
necessary helper methods required to validate a theme setting's value
This commit is contained in:
Alan Guo Xiang Tan
2024-02-21 08:08:26 +08:00
committed by GitHub
parent ec63f2b876
commit 6ca2396b12
10 changed files with 126 additions and 83 deletions

View File

@ -12,8 +12,4 @@ class ThemeSettingsManager::Integer < ThemeSettingsManager
def value=(new_value)
super(self.class.cast(new_value))
end
def is_valid_value?(new_value)
(@opts[:min]..@opts[:max]).include? new_value.to_i
end
end