Class: Rack::Sprockets::Base
- Inherits:
-
Object
- Object
- Rack::Sprockets::Base
- Includes:
- Options
- Defined in:
- lib/rack/sprockets/base.rb
Constant Summary
Constants included from Options
Options::COLLECTION_OPTS, Options::RACK_ENV_NS
Instance Method Summary collapse
-
#call(env) ⇒ Object
The Rack call interface.
-
#call!(env) ⇒ Object
The real Rack call interface.
-
#initialize(app, options = {}) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
Methods included from Options
Constructor Details
#initialize(app, options = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 |
# File 'lib/rack/sprockets/base.rb', line 9 def initialize(app, ={}) @app = app yield self if block_given? end |
Instance Method Details
#call(env) ⇒ Object
The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once
variable is set in the environment.
19 20 21 22 23 24 25 |
# File 'lib/rack/sprockets/base.rb', line 19 def call(env) if env['rack.run_once'] call! env else clone.call! env end end |
#call!(env) ⇒ Object
The real Rack call interface. if Sprockets JS is being requested, this is an endpoint:
> generate the compiled javascripts
> respond appropriately
Otherwise, call on up to the app as normal
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/sprockets/base.rb', line 32 def call!(env) @default_options.each { |k,v| env[k] ||= v } @env = env if (@request = Request.new(@env.dup.freeze)).for_sprockets? Response.new(@env.dup.freeze, @request.source.to_js).to_rack else @app.call(env) end end |