0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 01:40:29 +01:00
discourse-custom-wizard/extensions/custom_field/serializer.rb
Angus McLeod d453d97df3 Add custom-wizard-specific caching system
Initially for use with registered custom fields
2020-12-04 18:05:56 +11:00

39 Zeilen
Kein EOL
925 B
Ruby

module CustomWizardCustomFieldSerializer
def attributes(*args)
hash = super
if cw_fields_enabled?
@cw_klass = get_cw_class
if cw_fields.any?
cw_fields.each do |field|
if @cw_klass == "topic_view"
hash[field[:name].to_sym] = object.topic.custom_fields["#{field[:name]}"]
else
hash[field[:name].to_sym] = object.custom_fields["#{field[:name]}"]
end
end
end
end
hash
end
private
def cw_fields_enabled?
SiteSetting.custom_wizard_enabled && CustomWizard::CustomField.enabled?
end
def cw_fields
CustomWizard::CustomField.list_by(:serializers, @cw_klass)
end
def get_cw_class
self.class.ancestors.map do |klass|
klass.to_s.underscore.gsub("_serializer", "")
end.select do |klass|
CustomWizard::CustomField.serializers.include?(klass)
end.first
end
end