lib/copy/file.rb
# Parses the uploaded file to make the correct api request
#
# @param attributes [Hash] attributes to parse
# @return [Hash] parsed attributes hash
Parses the uploaded file to make the correct api request
Parses the uploaded file to make the correct api request
def parse_file(attrs)
        return attrs unless attrs[:file]
        attrs[:file_attrs] = {}
        if attrs[:file].kind_of?(::File) or attrs[:file].kind_of?(::Tempfile) then
          attrs[:file_attrs][:name] = attrs[:file].respond_to?(:original_filename) ? attrs[:file].original_filename : ::File.basename(attrs[:file].path)
          attrs[:file_attrs][:local_path] = attrs[:file].path
        elsif attrs[:file].kind_of?(String) then
          attrs[:file_attrs][:local_path] = attrs[:file]
          attrs[:file] = ::File.new(attrs[:file])
          attrs[:file_attrs][:name] = ::File.basename(attrs[:file_attrs][:local_path])
        elsif attrs[:file].kind_of?(StringIO) then
          raise(ArgumentError, "Must specify the :as option when uploading from StringIO") unless attrs[:as]
          attrs[:file_attrs][:local_path] = attrs[:as]
          class << file
            attr_accessor :path
          end
          file.path = attrs[:file]
        else
          raise ArgumentError, "local_file must be a File, StringIO, or file path"
        end
        attrs[:file_attrs][:name] = ::File.basename(attrs.delete(:as)) if attrs[:as]
        attrs
      end
def parse_file ( attrs ) return attrs unless attrs [ :file ] attrs [ :file_attrs ] = { } if attrs [ :file ] . kind_of? ( :: File ) or attrs [ :file ] . kind_of? ( :: Tempfile ) then attrs [ :file_attrs ] [ :name ] = attrs [ :file ] . respond_to? ( :original_filename ) ? attrs [ :file ] . original_filename : :: File . basename ( attrs [ :file ] . path ) attrs [ :file_attrs ] [ :local_path ] = attrs [ :file ] . path elsif attrs [ :file ] . kind_of? ( String ) then attrs [ :file_attrs ] [ :local_path ] = attrs [ :file ] attrs [ :file ] = :: File . new ( attrs [ :file ] ) attrs [ :file_attrs ] [ :name ] = :: File . basename ( attrs [ :file_attrs ] [ :local_path ] ) elsif attrs [ :file ] . kind_of? ( StringIO ) then raise ( ArgumentError , "Must specify the :as option when uploading from StringIO" ) unless attrs [ :as ] attrs [ :file_attrs ] [ :local_path ] = attrs [ :as ] class << file attr_accessor :path end file . path = attrs [ :file ] else raise ArgumentError , "local_file must be a File, StringIO, or file path" end attrs [ :file_attrs ] [ :name ] = :: File . basename ( attrs . delete ( :as ) ) if attrs [ :as ] attrs end
Parses the uploaded file to make the correct api request
Parses the uploaded file to make the correct api request
# hack for bug in UploadIO
parsed attributes hash
parsed attributes hash
Hash
attrs
<not_specific>
attributes
<not_specific>
attributes to parse
attributes to parse