Module: BigBand::Reloader

Defined in:
lib/big_band/reloader.rb

Overview

Advanced reloader for sinatra. Reloads only files that have changed and automatically detects orphaned routes that have to be removed. Files defining routes will be added to the reload list per default. Avoid reloading with dont_reload. Add other files to the reload list with also_reload.

Usage:

require "big_band"
class Foo < Sinatra::Base
  configure(:development) do
    register BigBand::Reloader
    also_reload "app/models/*.rb"
    dont_reload "lib/**/*.rb"
  end
end

Per default this will only be acitvated in development mode.

Defined Under Namespace

Modules: ClassMethods Classes: FileWatcher

Class Method Summary collapse

Class Method Details

.advanced_route_added(route) ⇒ Object



99
100
101
# File 'lib/big_band/reloader.rb', line 99

def self.advanced_route_added(route)
  FileWatcher.register(route)
end

.registered(klass) ⇒ Object



92
93
94
95
96
97
# File 'lib/big_band/reloader.rb', line 92

def self.registered(klass)
  klass.register AdvancedRoutes
  klass.extend ClassMethods
  klass.each_route { |route| advanced_route_added(route) }
  klass.before { Reloader.reload_routes }
end

.reload_routes(thread_safe = true) ⇒ Object



107
108
109
110
# File 'lib/big_band/reloader.rb', line 107

def self.reload_routes(thread_safe = true)
  return Thread.exclusive { reload_routes(false) } if thread_safe and thread_safe?
  FileWatcher.each { |file| file.reload }
end

.thread_safe?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/big_band/reloader.rb', line 103

def self.thread_safe?
  Thread and Thread.list.size > 1 and Thread.respond_to? :exclusive
end