Class: K8::UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/keight.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, content_type) ⇒ UploadedFile

Returns a new instance of UploadedFile.



602
603
604
605
606
607
608
609
610
# File 'lib/keight.rb', line 602

def initialize(filename, content_type)
  #; [!ityxj] takes filename and content type.
  @filename     = filename
  @content_type = content_type
  #; [!5c8w6] sets temporary filepath with random string.
  @tmp_filepath = new_filepath()
  #; [!8ezhr] yields with opened temporary file.
  File.open(@tmp_filepath, 'wb') {|f| yield f } if block_given?
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



612
613
614
# File 'lib/keight.rb', line 612

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



612
613
614
# File 'lib/keight.rb', line 612

def filename
  @filename
end

#tmp_filepathObject (readonly)

Returns the value of attribute tmp_filepath.



612
613
614
# File 'lib/keight.rb', line 612

def tmp_filepath
  @tmp_filepath
end

Instance Method Details

#cleanObject



614
615
616
617
618
619
# File 'lib/keight.rb', line 614

def clean
  #; [!ft454] removes temporary file if exists.
  File.unlink(@tmp_filepath) if @tmp_filepath
rescue SystemCallError   # or Errno::ENOENT?
  nil
end