Class: Plum::ThemeSettingsParams

Inherits:
Object
  • Object
show all
Defined in:
app/services/plum/theme_settings_params.rb

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ ThemeSettingsParams

Returns a new instance of ThemeSettingsParams.



3
4
5
# File 'app/services/plum/theme_settings_params.rb', line 3

def initialize(theme)
  @theme = theme
end

Instance Method Details

#normalize(raw_settings) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/plum/theme_settings_params.rb', line 7

def normalize(raw_settings)
  raw_settings = raw_settings.to_h.stringify_keys

  theme.settings_fields.each_with_object({}) do |field, settings|
    handle = field["handle"].to_s
    next if handle.blank?

    value = raw_settings.key?(handle) ? raw_settings[handle] : field["default"]
    settings[handle] = normalize_value(field, value)
  end
end