Sha256: ce1a6542555b5ac9fabdece46f0e37ed7df28897c66af4940d331afba306115d
Contents?: true
Size: 878 Bytes
Versions: 9
Compression:
Stored size: 878 Bytes
Contents
module DataMapper class Property class ParseFile < Object def dump(value) case value when ::URI { "__type" => "File", "name" => File.basename(value.path), "url" => value.to_s } when ::Hash value end end def load(value) value && URI(value["url"]) end def typecast(value) if value.respond_to?(:original_filename) && value.respond_to?(:read) && value.respond_to?(:content_type) adapter = model.repository.adapter filename = value.original_filename content = value.read content_type = value.content_type response = adapter.upload_file(filename, content, content_type) URI(response["url"]) elsif value.is_a?(Hash) URI(value["url"]) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems