Sha256: 5dd073197ae166c603d9b462e5dbd2b9dd76f521a9f8e43bcca1643e136d4f68

Contents?: true

Size: 923 Bytes

Versions: 11

Compression:

Stored size: 923 Bytes

Contents

module ScrewUnit
  module Resources
    class File
      attr_reader :virtual_path, :asset_manager
      def initialize(virtual_path, asset_manager)
        @virtual_path, @asset_manager = virtual_path, asset_manager
      end

      def physical_path
        asset_manager.physicalize_path(virtual_path)
      end

      def get
        [200, headers, ::File.read(physical_path)]
      end

      MIME_TYPES = {
        ".css" => "text/css",
        ".gif" => "image/gif",
        ".js" => "application/javascript",
        ".jpg" => "image/jpeg",
        ".jpeg" => "image/jpeg",
        ".png" => "image/png",
        }

      def headers
        {
          "Content-Type" => mime_type(physical_path),
          "Last-Modified" => ::File.mtime(physical_path).httpdate
        }
      end

      protected

      def mime_type(physical_path)
        MIME_TYPES[::File.extname(physical_path)]
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
coolerator.vision-0.2.10 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.9 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.8 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.7 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.6 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.5 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.4 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.3 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.2 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.1 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb
coolerator.vision-0.2.0 spec/support/vendor/screw-unit/lib/screw_unit/resources/file.rb