The contents model is quite flexible right now, but it's still a bit restrictive for things that extrapolate the title+description+images combination.
By adding a custom_attributes field in the cas_contents field, we can add any new input to the forms without having to change database schema. By configuring cas.yml, this format can be checked out on Git so developers can review changes.
Acceptance criteria
Technical details
I imagine the model to have something similar to the following pseudocode:
class Cas::Content < ActiveRecord::Base
CUSTOM_ATTRIBUTES_KEYS = ["key", "value"].freeze
# ...
# `custom_attributes` has the following format:
#
# [{
# "key": "name",
# "value": "John Doe"
# }]
#
# The type of the field (string|integer|boolean) are stored in the yml file
def custom_attributes=(value)
self[:custom_attributes] = value.map do |hash|
hash.keep_if { |key, _| CUSTOM_ATTRIBUTES_KEYS.include?(key.to_s) }
end
end
def custom_attribute(key)
Array.wrap(custom_attributes).find { |attr| attr["key"] == key.to_s } || {}
end
# ...
end
The
contentsmodel is quite flexible right now, but it's still a bit restrictive for things that extrapolate the title+description+images combination.By adding a
custom_attributesfield in thecas_contentsfield, we can add any new input to the forms without having to change database schema. By configuring cas.yml, this format can be checked out on Git so developers can review changes.Acceptance criteria
custom_attributesJSONB column (array) tocas_contentstable.Cas::Contentmodel for saving and retrieving custom attributesTechnical details
I imagine the model to have something similar to the following pseudocode: