Class: Assets::Compiler::Plugin::Rack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, dwell = 1.0) ⇒ Rack

Initialize the middleware.

Parameters:

  • app (#call)

    The Rack application

  • dwell (Float) (defaults to: 1.0)

    See #dwell



17
18
19
20
21
# File 'lib/assets/compiler/plugin/rack.rb', line 17

def initialize(app, dwell = 1.0)
	@app = app
	@dwell = dwell
	@check_after = Time.now.to_f
end

Instance Attribute Details

#dwellFloat

The delay, in seconds, between update checks. Useful when many resources are requested for a single page. ‘nil` means no delay at all.

Returns:

  • (Float)


11
12
13
# File 'lib/assets/compiler/plugin/rack.rb', line 11

def dwell
  @dwell
end

Instance Method Details

#call(env) ⇒ (#to_i, {String => String}, Object)

Returns The Rack response.

Parameters:

  • env

    The Rack request environment

Returns:

  • ((#to_i, {String => String}, Object))

    The Rack response



25
26
27
28
29
30
31
# File 'lib/assets/compiler/plugin/rack.rb', line 25

def call(env)
	if @dwell.nil? || Time.now.to_f > @check_after
		Assets::Compiler.compile!
		@check_after = Time.now.to_f + @dwell if @dwell
	end
	@app.call(env)
end