Sha256: e840c5d34d3bfaaf7c7d6302c4300e1ae9aa0335aa1b551c9d20bc844467b6be
Contents?: true
Size: 1.22 KB
Versions: 23
Compression:
Stored size: 1.22 KB
Contents
module Scrivito module Backend class ObjDataFromRest < ObjData def initialize(data) raise InternalError unless Hash === data @data = data end def raw_value_and_type_of(attribute_name) return [value_of_widget_pool, nil] if attribute_name == '_widget_pool' if attribute_data = @data[attribute_name] if attribute_name.starts_with?('_') [attribute_data, nil] else type = attribute_data[0] [legacy_compatible(attribute_data[1], type), type] end else [nil, nil] end end def attribute_names @data.keys end def to_h @data end private def legacy_compatible(value, type) if type == "linklist" value.map(&method(:legacy_link)) elsif type == "link" legacy_link(value) else value end end def legacy_link(link) return link unless link["obj_id"] transformed = link.dup transformed["destination"] = transformed.delete("obj_id") transformed end def value_of_widget_pool if widget_pool = @data['_widget_pool'] # using Hash#merge to "map" to a new Hash widget_pool.merge(widget_pool) do |id, raw_widget_data| self.class.new(raw_widget_data) end end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems