Class: Rack::JasmineFile

Inherits:
File
  • Object
show all
Defined in:
lib/jasmine-sprockets/jasmine_file.rb

Constant Summary collapse

@@cache =
{}

Instance Method Summary collapse

Instance Method Details

#servingObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jasmine-sprockets/jasmine_file.rb', line 13

def serving
  unless @@cache[@path] && @@cache[@path][0] >= F.mtime(@path)
    @@cache[@path] = [F.mtime(@path), sprocket[@path]]
  end
  base  = @@cache[@path][1]
  ctype = base.content_type

  body = [base.to_s]
  size = Utils.bytesize(body.first)

  [200, {
    "Last-Modified"   => F.mtime(@path).httpdate,
    "Cache-Control"   => "must-revalidate",
    "Content-Type"    => ctype || Mime.mime_type(F.extname(@path), 'text/plain'),
    "Content-Length"  => size.to_s
  }, body]
end

#sprocketObject



9
10
11
# File 'lib/jasmine-sprockets/jasmine_file.rb', line 9

def sprocket
  @sprocket ||= ::Sprockets::Environment.new.tap{|s| s.append_path @root}
end