Class: Waw::Restart

Inherits:
Object show all
Includes:
Rack::Delegator
Defined in:
lib/waw/restart.rb

Constant Summary collapse

DEFAULT_OPTIONS =

Default options

{ :when => :always }

Instance Method Summary collapse

Methods included from Rack::Delegator

#_visit, #delegate, #find_rack_app, #find_url_of, #has_delegate?, #is_delegate?, #visit

Constructor Details

#initialize(app, opts = {}, lock = Mutex.new) ⇒ Restart

Creates a restarter instance



9
10
11
12
13
# File 'lib/waw/restart.rb', line 9

def initialize(app, opts = {}, lock = Mutex.new)
  @options = DEFAULT_OPTIONS.merge(opts)
  @app = app
  @lock = lock
end

Instance Method Details

#call(env) ⇒ Object

Handle the call



21
22
23
24
25
26
27
28
29
# File 'lib/waw/restart.rb', line 21

def call(env)
  if restart?
    @lock.synchronize do
      root_folder = Waw.root_folder
      Waw.reload
    end
  end
  @app.call(env)
end

#restart?Boolean

Should I need to restart?

Returns:



16
17
18
# File 'lib/waw/restart.rb', line 16

def restart?
  @options[:when] == :always
end