Class: Grape::ReloadMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/reload/grape_api.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ReloadMiddleware

Returns a new instance of ReloadMiddleware.



19
20
21
# File 'lib/grape/reload/grape_api.rb', line 19

def initialize(app)
  @app_klass = app
end

Class Method Details

.[](threshold) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/grape/reload/grape_api.rb', line 6

def [](threshold)
  threshold ||= 2
  eval <<CLASS
Class.new(Grape::ReloadMiddleware) {
  private
  def reload_threshold
    #{threshold > 0 ? threshold.to_s+".seconds" : "false" }
  end
}
CLASS
end

Instance Method Details

#call(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/grape/reload/grape_api.rb', line 23

def call(*args)
  if reload_threshold && (Time.now > (@last || reload_threshold.ago) + 1)
    Thread.list.size > 1 ? Thread.exclusive { Grape::Reload::Watcher.reload! } : Grape::Reload::Watcher.reload!
    @last = Time.now
  else
    Thread.list.size > 1 ? Thread.exclusive { Grape::Reload::Watcher.reload! } : Grape::Reload::Watcher.reload!
  end
  @app_klass.constantize.call(*args)
end

#reload_thresholdObject



32
# File 'lib/grape/reload/grape_api.rb', line 32

def reload_threshold; 2.seconds end