Sha256: abdfdca954b447f8cf22b1d64972a83d6153a08b09d02107bd831caef3d5ea73
Contents?: true
Size: 966 Bytes
Versions: 3
Compression:
Stored size: 966 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 = Digest::SHA256.new.hexdigest 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"]) elsif value.is_a?(::String) URI(value) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dm-parse-0.3.20 | lib/property/parse_file.rb |
dm-parse-0.3.19 | lib/property/parse_file.rb |
dm-parse-0.3.18 | lib/property/parse_file.rb |