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 [attribute_data[1], attribute_data[0]] end else [nil, nil] end end def attribute_names @data.keys end def to_h @data end private 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