Module: FileUploadIO

Defined in:
lib/file_upload_io.rb

Class Method Summary collapse

Class Method Details

.new(file_path, content_type) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/file_upload_io.rb', line 2

def self.new(file_path, content_type)
  raise ArgumentError, "File content type required" unless content_type
  file_io = File.open(file_path, "rb")
  file_io.instance_eval(<<-EOS, __FILE__, __LINE__)
    def content_type
      "#{content_type}"
    end

    def file_name
      "#{File.basename(file_path)}"
    end

    def file_size
      "#{File.size(file_path)}".to_i
    end
  EOS
  file_io
end