Class: Rack::Tipi::Assets
- Inherits:
-
Object
- Object
- Rack::Tipi::Assets
- Defined in:
- lib/rack/tipi/assets.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#tipi_root ⇒ Object
readonly
Returns the value of attribute tipi_root.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ Assets
constructor
A new instance of Assets.
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, ) @app = app @tipi_root = [:tipi_root] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/rack/tipi/assets.rb', line 6 def app @app end |
#tipi_root ⇒ Object (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 |
.resources ⇒ Object
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 |