2024-02-07 23:59:52 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ThemeSettingsManager::Objects < ThemeSettingsManager
|
2024-04-25 09:39:22 -04:00
|
|
|
def self.extract_value_from_row(row)
|
|
|
|
row.json_value
|
|
|
|
end
|
|
|
|
|
2024-02-07 23:59:52 -05:00
|
|
|
def value
|
|
|
|
has_record? ? db_record.json_value : default.map!(&:deep_stringify_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
def value=(objects)
|
2024-03-10 20:42:12 -04:00
|
|
|
objects = JSON.parse(objects) if objects.is_a?(::String)
|
2024-02-27 21:33:22 -05:00
|
|
|
ensure_is_valid_value!(objects)
|
2024-03-07 03:38:11 -05:00
|
|
|
record = has_record? ? update_record!(json_value: objects) : create_record!(json_value: objects)
|
2024-02-07 23:59:52 -05:00
|
|
|
theme.reload
|
|
|
|
record.json_value
|
|
|
|
end
|
2024-03-05 19:24:29 -05:00
|
|
|
|
|
|
|
def schema
|
|
|
|
@opts[:schema]
|
|
|
|
end
|
2024-03-26 22:54:30 -04:00
|
|
|
|
|
|
|
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
|
2024-02-07 23:59:52 -05:00
|
|
|
end
|