def assign(file, identifier = Identifier.generate)
      self.file = file

      if file
        extension ||= file.extension if file.respond_to? :extension
        extension ||= File.extname(file.original_filename) if file.respond_to? :original_filename
        extension ||= File.extname(file.path) if file.respond_to? :path
        size ||= file.size if file.respond_to? :size
        size ||= File.size(file.path) if file.respond_to? :path
      end

      @purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if attached?

      self.size       = file ? size       : nil
      self.extension  = file ? extension  : nil
      self.identifier = file ? identifier : nil

      process if file
    end
def assign(file, identifier = Identifier.generate)
      self.file = file

      if file
        extension ||= file.extension if file.respond_to? :extension
        extension ||= File.extname(file.original_filename) if file.respond_to? :original_filename
        extension ||= File.extname(file.path) if file.respond_to? :path
        size ||= file.size if file.respond_to? :size
        size ||= File.size(file.path) if file.respond_to? :path
      end

      @purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if attached?

      self.size       = file ? size       : nil
      self.extension  = file ? extension  : nil
      self.identifier = file ? identifier : nil

      process if file
    end
Assign an attachment to a file.

 Usage:

   @object.avatar.assign(...)