Sha256: e29115a11743849a9e069aaa52f0d303f6b2eab6e9db0066baeb302ad1700afa
Contents?: true
Size: 1.19 KB
Versions: 4
Compression:
Stored size: 1.19 KB
Contents
module Scrivito class CmsRestApi class WidgetExtractor # Extract widgets from a given attribute tree and return them as a flat # hash of widget_like => updated_attributes def self.call(updated_attributes, obj=nil) extracted_widgets = {} updated_attributes.each do |attribute_name, value| if value.is_a?(Array) && value.all? {|w| w.is_a?(BasicWidget)} value.each do |widget| unless widget.persisted? widget.id = if obj.present? obj.generate_widget_pool_id else BasicObj.generate_widget_pool_id end widget.obj = obj extracted_widgets[widget] = widget.attributes_to_be_saved extracted_widgets.merge!(self.call(widget.attributes_to_be_saved, obj)) end end end end extracted_widgets end def self.notify_persisted_widgets(obj, widget_hash) widget_hash.each do |widget, attributes| if attributes.present? widget.obj = obj widget.forget_unsaved_attribtues end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems