Class: Rack::Tipi::Assets

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/tipi/assets.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ Assets

Returns a new instance of Assets.



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

def initialize(app, options)
  @app = app
  @tipi_root = options[:tipi_root]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#tipi_rootObject (readonly)

Returns the value of attribute tipi_root.



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

def tipi_root
  @tipi_root
end

Class Method Details

.register(namespace, path, route) ⇒ Object



29
30
31
32
# File 'lib/rack/tipi/assets.rb', line 29

def self.register(namespace, path, route)
  asset = Asset.new(namespace, path, route)
  (@resources ||= []) << asset unless resources.include? asset
end

.resourcesObject



25
26
27
# File 'lib/rack/tipi/assets.rb', line 25

def self.resources
  @resources || []
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/tipi/assets.rb', line 13

def call(env)
  asset = self.class.resources.detect do |a|
    "#{tipi_root}#{a.route}" == env['REQUEST_PATH']
  end

  if asset
    [ 200, { 'Content-Type' => asset.mime_type }, [ asset.content ] ]
  else
    app.call(env)
  end
end