Permalink
Browse files

Merge pull request #1432 from padrino/refactor-reloader

Refactor reloader, closes #1427
  • Loading branch information...
ujifgc committed Oct 6, 2013
2 parents 8d626a1 + 57de52b commit 3e0bf1b3e128063d244b5139596d147a0c53bc32
@@ -54,7 +54,7 @@ def inherited(base)
# MyApp.reload!
#
def reload!
logger.devel "Reloading #{settings}"
logger.devel "Reloading application #{settings}"
reset!
reset_router!
Padrino.require_dependencies(settings.app_file, :force => true) # Reload the app file
@@ -103,6 +103,7 @@ def setup_application!
settings.default_routes!
settings.default_errors!
if defined?(I18n)
Reloader.special_files += settings.locale_path
I18n.load_path << settings.locale_path
I18n.reload!
end
@@ -71,7 +71,7 @@ def load!
Padrino.before_load.each(&:call) # Run before hooks
Padrino.dependency_paths.each { |path| Padrino.require_dependencies(path) }
Padrino.after_load.each(&:call) # Run after hooks
Padrino::Reloader.run!
Padrino::Reloader.changed?
Thread.current[:padrino_loaded] = true
Padrino.logger.devel "Loaded Padrino in #{Time.now - t} seconds"
@@ -147,35 +147,35 @@ def loaded?
# require_dependencies("#{Padrino.root}/lib/**/*.rb")
#
def require_dependencies(*paths)
options = paths.extract_options!
options = paths.extract_options!.merge( :cyclic => true )
# Extract all files to load
files = paths.flatten.map { |path| Dir[path] }.flatten.uniq.sort
while files.present?
errors, failed = [], []
errors, fatal = [], false
size_at_start = files.size
# Now we try to require our dependencies, we dup files
# so we don't perform delete on the original array during
# iteration, this prevent problems with Rubinus
files.dup.each do |file|
begin
Padrino::Reloader.safe_load(file, options.dup)
Padrino::Reloader.safe_load(file, options)
files.delete(file)
rescue NameError, LoadError => e
Padrino.logger.devel "Problem while loading #{file}: #{e}"
logger.devel "Cyclic dependency reload for #{e.message}"
errors << e
failed << file
rescue Exception => e
raise e
errors << e
fatal = true
break
end
end
# Stop processing if nothing loads or if everything has loaded
raise errors.last if files.size == size_at_start && files.present?
break if files.empty?
# Stop processing if error is fatal or nothing loads in cycle
if fatal || files.size == size_at_start && files.present?
e = errors.last
logger.error "#{e.class}: #{e.message}; #{e.backtrace.first}"
raise e
end
end
end
Oops, something went wrong.

0 comments on commit 3e0bf1b

Please sign in to comment.