markbates / mack

A Ruby web application framework

This URL has Read+Write access

mack / lib / mack / testing / file.rb
100644 29 lines (26 sloc) 0.745 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'base64'
module Mack
  module Testing
    class FileWrapper # :nodoc:
      
      attr_reader :path
      attr_reader :file_name
      attr_reader :content
      attr_reader :size
      attr_reader :mime
      
      def initialize(path)
        @path = path
        @file_name = File.basename(path)
        extension = File.extname(path)
        extension = extension.gsub!(".", "")
        if extension and !extension.empty?
          @mime = Mack::Utils::MimeTypes.instance.get(extension) if extension
        else
          @mime = "application/octet-stream"
        end
        raw_content = File.read(path)
        @content = Base64.encode64(raw_content).strip
        @size = @content.size
      end
    end
  end
end