Parent

Included Modules

Class Index [+]

Quicksearch

Ramaze::Reloader

High performant source reloader

This class acts as Rack middleware.

It does not depend on Ramaze itself, but you might have to adjust the Reloader::Hooks module or include your own module to override the hooks. You also might have to set the Log constant.

Currently, it uses RInotify if available and falls back to using File.stat.

Please note that this will not reload files in the background, it does so only when actively called In case of Ramaze it is performing a check/reload cycle at the start of every request, but also respects a cool down time, during which nothing will be done.

After every reload the OPTIONS hash will be checked for changed options and assigned to the instance, so you may change options during the lifetime of your application.

A number of hooks will be executed during the reload cycle, see Ramaze::ReloaderHooks for more information.

Constants

OPTIONS
Watcher
Watcher

Public Class Methods

new(app) click to toggle source

Creates a new instance of the class and saves the application it has to watch.

@author Michael Fellinger @since 09-08-2008 @param [Ramaze::App] app The application to monitor.

    # File lib/ramaze/reloader.rb, line 71
71:     def initialize(app)
72:       @app = app
73:       @files = {}
74:       @watcher = Watcher.new
75:       options_reload
76:     end

Public Instance Methods

call(env) click to toggle source

Allows this class to be called as a Rack middleware.

@author Michael Fellinger @since 09-08-2008 @param [Hash] env A hash containing all environment details.

     # File lib/ramaze/reloader.rb, line 97
 97:     def call(env)
 98:       options_reload
 99: 
100:       @watcher.call(@cooldown) do
101:         if @control
102:           instance_eval(&@control)
103:         elsif @thread
104:           Thread.exclusive{ cycle }
105:         else
106:           cycle
107:         end
108:       end
109: 
110:       @app.call(env)
111:     end
cycle() click to toggle source

Loops through all the files and reloads all changes files.

@author Michael Fellinger @since 09-08-2008

     # File lib/ramaze/reloader.rb, line 119
119:     def cycle
120:       before_cycle
121: 
122:       rotation{|file| @watcher.watch(file) }
123:       @watcher.changed_files{|f| safe_load(f) }
124: 
125:       after_cycle
126:     end
figure_path(file, paths) click to toggle source

Tries to find a given file in an array of file paths.

@author Michael Fellinger @since 09-08-2008 @param [String] file The name of the file to look for. @param [Array] paths An array of paths to search. @return [String]

     # File lib/ramaze/reloader.rb, line 166
166:     def figure_path(file, paths)
167:       if Pathname.new(file).absolute?
168:         return File.exist?(file) ? file : nil
169:       end
170: 
171:       paths.each do |possible_path|
172:         full_path = File.join(possible_path, file)
173:         return full_path if File.exist?(full_path)
174:       end
175:       nil
176:     end
options_reload() click to toggle source

Returns all the options for this class.

@author Michael Fellinger @since 09-08-2008 @return [Array]

    # File lib/ramaze/reloader.rb, line 85
85:     def options_reload
86:       @cooldown, @ignore, @control, @thread =
87:         OPTIONS.values_at(:cooldown, :ignore, :control, :thread)
88:     end
rotation() click to toggle source
     # File lib/ramaze/reloader.rb, line 144
144:     def rotation
145:       files = [$0, __FILE__, *$LOADED_FEATURES].uniq
146:       paths = ['./', *$LOAD_PATH].uniq
147: 
148:       files.each do |file|
149:         next if file =~ @ignore
150:         if not @files.has_key?(file) and path = figure_path(file, paths)
151:           @files[file] = path
152:           yield path
153:         end
154:       end
155:     end
safe_load(file) click to toggle source

A safe Kernel::load, issuing the hooks depending on the results

@author Michael Fellinger @since 09-08-2008 @param [String] file Path to the file to safely load.

     # File lib/ramaze/reloader.rb, line 135
135:     def safe_load(file)
136:       before_safe_load(file)
137:       load(file)
138:       after_safe_load_succeed(file)
139:     rescue Object => ex
140:       Log.error(ex)
141:       after_safe_load_failed(file, ex)
142:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.