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

Returns a new instance of RouteReloader.



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

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
# File 'lib/rails-brochure/route_reloader.rb', line 9

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

#last_route_changeObject



26
27
28
# File 'lib/rails-brochure/route_reloader.rb', line 26

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

#new_content?Boolean

Returns:

  • (Boolean)


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

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

#reload_routesObject



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

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