Sha256: 2b9be8b95f6b4654c993b511a468e82ced36e619f4fc510d23207fc5744cb700
Contents?: true
Size: 1.76 KB
Versions: 13
Compression:
Stored size: 1.76 KB
Contents
module Scrivito module ObjParamsParser class UnknownWidgetAction < ScrivitoError end def parse(params) params = params.deep_dup convert_params(params) params end private def convert_field_params(obj_class, params) params.each_pair do |key, value| if key.to_s == 'blob' && obj_class.legacy_type? params[key] = parse_binary_field_params(value) next end params[key] = case type = obj_class.attributes[key].try(:type) when 'html' then ContentConversion.convert_html_links(value, host, port) when 'linklist' then ContentConversion.convert_linklist_urls(value, host, port) when 'link' then ContentConversion.convert_link(value, host, port) when 'widget' then parse_widget_field_params(value) when 'binary' then parse_binary_field_params(value) else value end end end def parse_widget_field_params(params) params.map do |widget_id_or_params| if widget_id_or_params.is_a?(Hash) action, widget_params = widget_id_or_params.flatten case action when 'create' then Widget.new(widget_params) when 'copy' widget_id = widget_params['widget_id'] widget = Workspace.find(widget_params['workspace_id']) .objs.find(widget_params['obj_id']) .widgets[widget_id] raise ResourceNotFound, "Could not find Widget with id #{widget_id}" unless widget widget.copy else raise UnknownWidgetAction end else obj.widgets[widget_id_or_params] end end end def parse_binary_field_params(params) UploadedBinary.new(params) if params end end end
Version data entries
13 entries across 13 versions & 1 rubygems