Sha256: 46fadd397f1df0434d494f9133cf0137e91bf83e433b150ac44130df4839b593

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

module DataMapper
  class Property

    class ParseFile < Object

      def dump(value)
        value && { "__type" => "File", "name" => File.basename(value.path) }
      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"])
        end
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-parse-0.3.3 lib/property/parse_file.rb