Class: Rails::Brochure::RouteReloader

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-brochure/route_reloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RouteReloader



4
5
6
# File 'lib/rails-brochure/route_reloader.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
# File 'lib/rails-brochure/route_reloader.rb', line 7

def call(env)
  reload_routes if new_content?
  @app.call(env)
end

#last_route_changeObject



21
22
23
# File 'lib/rails-brochure/route_reloader.rb', line 21

def last_route_change
  File.mtime("config/routes.rb")
end

#new_content?Boolean



17
18
19
20
# File 'lib/rails-brochure/route_reloader.rb', line 17

def new_content?
  return true if HomeContent.newest.nil? || last_route_change.nil?
  HomeContent.newest > last_route_change
end

#reload_routesObject



11
12
13
14
15
16
# File 'lib/rails-brochure/route_reloader.rb', line 11

def reload_routes
  # we must touch the routes file in order for it to be reloaded    
  FileUtils.touch("config/routes.rb")
  Rails.application.reload_routes!
  Rails.logger.info "ROUTES RELOADED by rails-brochure"
end