Created
June 24, 2010 00:56
Revisions
-
gmalamid revised this gist
Jun 24, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,8 @@ module Sinatra module Reloader def self.extended(target) target.before { target.reload } default_path = File.expand_path(File.join(File.dirname(__FILE__), '**', '*.rb')) target.set(:reload_paths, [default_path]) end def reload -
gmalamid revised this gist
Jun 24, 2010 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,12 +14,15 @@ # end # # :reload_paths should be an array of path patterns where the # source code intended for reloading resides. # If not set, default is '<sinatra_reloader_dir>/**/*.rb' module Sinatra module Reloader def self.extended(target) target.before { target.reload } default_path = [File.expand_path(File.join(File.dirname(__FILE__), '**', '*.rb'))] target.set(:reload_paths, default_path) end def reload -
gmalamid revised this gist
Jun 24, 2010 . 1 changed file with 5 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,19 +23,15 @@ def self.extended(target) end def reload source_files = reload_paths.inject({}) do |paths, pattern| Dir[pattern].each { |path| paths[path] = File.mtime(path) } paths end return if source_files == @source_files @source_files = source_files routes.clear @source_files.keys.each { |path| load(path) } end end register Reloader -
gmalamid created this gist
Jun 24, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ # For "Classic" style/top-level type of apps do something like: # # configure :development do # require File.join(File.dirname(__FILE__), 'sinatra_reloader') # set :reload_paths, [File.join(File.dirname(__FILE__), '**', '*.rb')] # end # # For "Modular" style/Sinatra::Base subclasses: # # configure :development do # require File.join(File.dirname(__FILE__), 'sinatra_reloader') # register Sinatra::Reloader # set :reload_paths, [File.join(File.dirname(__FILE__), '**', '*.rb')] # end # # :reload_paths should be an array of path patterns where the # source code intended for reloading resides module Sinatra module Reloader def self.extended(target) target.before { target.reload } end def reload source_files = scan_reload_paths return if source_files == @source_files @source_files = source_files routes.clear @source_files.keys.each { |path| load(path) } end def scan_reload_paths reload_paths.inject({}) do |paths, pattern| Dir[pattern].each { |path| paths[path] = File.mtime(path) } paths end end end register Reloader end