module Scrivito class ObjCreateParamsParser < Struct.new(:host, :port, :context) def parse(params) params = params.deep_dup convert_params(params) params end private def convert_params(params) if obj_class = params['_obj_class'] obj_class = Obj.type_computer.compute_type_without_fallback(obj_class) convert_field_params(params, obj_class.attribute_definitions) else raise ArgumentError, 'Missing "_obj_class" param' end end def convert_field_params(params, attribute_definitions) params.each_pair do |key, value| params[key] = case 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 'date' then DateConversion.deserialize_from_client(value) else value end end end def parse_binary_params(params) return unless params UploadedBinary.new(params) end end end