Class: Rack::Jspm

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/jspm.rb,
lib/rack/jspm/version.rb

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Jspm

Returns a new instance of Jspm.



8
9
10
11
# File 'lib/rack/jspm.rb', line 8

def initialize(app, options = {})
  @app = app
  @options = { max_age: 3600 }.merge(options)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/rack/jspm.rb', line 6

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/rack/jspm.rb', line 6

def options
  @options
end

Instance Method Details

#cache_controlObject



26
27
28
# File 'lib/rack/jspm.rb', line 26

def cache_control
  { 'Cache-Control' => "max-age=#{max_age}, public" }
end

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rack/jspm.rb', line 13

def call(env)
  status, headers, body = @app.call(env)
  case env['PATH_INFO']
    when %r{/jspm_packages/[^/]+/}
      headers = headers.merge(cache_control)
  end
  [status, headers, body]
end

#max_ageObject



22
23
24
# File 'lib/rack/jspm.rb', line 22

def max_age
  options.fetch(:max_age)
end