Class: ThemeSettingsManager::Objects

Inherits:
ThemeSettingsManager show all
Defined in:
lib/theme_settings_manager/objects.rb

Instance Attribute Summary

Attributes inherited from ThemeSettingsManager

#default, #name, #theme

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThemeSettingsManager

cast, cast_row_value, create, #create_record!, #db_record, #description, #ensure_is_valid_value!, #has_max?, #has_min?, #has_record?, #initialize, #requests_refresh?, #type, #type_name, types, #update_record!

Constructor Details

This class inherits a constructor from ThemeSettingsManager

Class Method Details

.extract_value_from_row(row) ⇒ Object



4
5
6
# File 'lib/theme_settings_manager/objects.rb', line 4

def self.extract_value_from_row(row)
  row.json_value
end

Instance Method Details

#categories(guardian) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/theme_settings_manager/objects.rb', line 24

def categories(guardian)
  category_ids = Set.new

  value.each do |theme_setting_object|
    category_ids.merge(
      ThemeSettingsObjectValidator.new(
        schema:,
        object: theme_setting_object,
      ).property_values_of_type("categories"),
    )
  end

  return [] if category_ids.empty?

  Category.secured(guardian).where(id: category_ids)
end

#schemaObject



20
21
22
# File 'lib/theme_settings_manager/objects.rb', line 20

def schema
  @opts[:schema]
end

#valueObject



8
9
10
# File 'lib/theme_settings_manager/objects.rb', line 8

def value
  has_record? ? db_record.json_value : default.map!(&:deep_stringify_keys)
end

#value=(objects) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/theme_settings_manager/objects.rb', line 12

def value=(objects)
  objects = JSON.parse(objects) if objects.is_a?(::String)
  ensure_is_valid_value!(objects)
  record = has_record? ? update_record!(json_value: objects) : create_record!(json_value: objects)
  theme.reload
  record.json_value
end