Sha256: 9dec4a8c2dbadcf5103444ff10a17ccc4ce0364ad058c1e982aa87b7f3cb263f
Contents?: true
Size: 1.83 KB
Versions: 8
Compression:
Stored size: 1.83 KB
Contents
module Scrivito class ObjParamsParser < Struct.new(:host, :port, :context) class UnknownWidgetAction < ScrivitoError end def parse(params) params = params.deep_dup convert_params(params) params end private def convert_field_params(params, attribute_definitions) params.each_pair do |key, value| params[key] = case type = attribute_definitions[key.to_s].try(:type) when 'binary' then parse_binary_params(value) when 'html' then ContentConversion.convert_html_links(value, host, port) when 'link' then ContentConversion.convert_link(value, host, port) when 'linklist' then ContentConversion.convert_linklist_urls(value, host, port) when 'widgetlist' then parse_widgetlist_params(value) when 'date' then parse_date_params(value) else value end end end def parse_widgetlist_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, context.slice(:scrivito_user)) 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_params(params) UploadedBinary.new(params) if params end def parse_date_params(params) DateAttribute.parse(params) end end end
Version data entries
8 entries across 8 versions & 1 rubygems