Class: Rack::Manifest

Inherits:
Object
  • Object
show all
Includes:
Sprockets
Defined in:
lib/rack/manifest/version.rb,
lib/rack/manifest.rb

Defined Under Namespace

Modules: Sprockets Classes: Railtie

Constant Summary collapse

VERSION =
"0.1.4"
FILE_PATH =
'./config/manifest.yml'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Manifest

Returns a new instance of Manifest.



19
20
21
# File 'lib/rack/manifest.rb', line 19

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rack/manifest.rb', line 23

def call(env)
  if env['PATH_INFO'] == '/manifest.json'
    manifest = load_yaml(FILE_PATH)
    json = JSON.generate(manifest)
    etag = digest(json)
    return [304, {}, []] if env['HTTP_IF_NONE_MATCH'] == etag
    [
      200,
      {
        'Content-Type' => 'application/json',
        'Etag' => etag,
        'Content-Length' => json.length.to_s
      },
      [json]
    ]
  else
    @app.call(env)
  end
end

#load_yaml(path) ⇒ Object



14
15
16
# File 'lib/rack/manifest.rb', line 14

def load_yaml path
  YAML.load(ERB.new(File.read(path)).result)
end