Class: Releaf::Content::RoutesReloader

Inherits:
Object
  • Object
show all
Defined in:
lib/releaf/content/routes_reloader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RoutesReloader

Returns a new instance of RoutesReloader.



3
4
5
6
# File 'lib/releaf/content/routes_reloader.rb', line 3

def initialize(app)
  @app = app
  self.class.routes_loaded
end

Class Method Details

.needs_reload?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/releaf/content/routes_reloader.rb', line 27

def self.needs_reload?
  Releaf::Content.models.any? do | node_class |
    node_class.updated_at.present? && (@updated_at.nil? || @updated_at < node_class.updated_at)
  end
end

.reload_if_neededObject



21
22
23
24
25
# File 'lib/releaf/content/routes_reloader.rb', line 21

def self.reload_if_needed
  return unless needs_reload?
  Rails.application.reload_routes!
  routes_loaded
end

.reset!Object



13
14
15
# File 'lib/releaf/content/routes_reloader.rb', line 13

def self.reset!
  @updated_at = nil
end

.routes_loadedObject



17
18
19
# File 'lib/releaf/content/routes_reloader.rb', line 17

def self.routes_loaded
  @updated_at = Time.now
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
# File 'lib/releaf/content/routes_reloader.rb', line 8

def call(env)
  self.class.reload_if_needed
  @app.call(env)
end