Trying to return from a block is a bad idea

This commit is contained in:
Thomas Reynolds 2012-09-13 10:51:16 -07:00
parent 06578c61fa
commit 77be952d41
3 changed files with 18 additions and 29 deletions

View file

@ -1,7 +1,7 @@
Master
===
3.0.3
3.0.3-3.0.4
====
* Add reload_paths to server CLI to add additional paths to reload MM on change.
* Re-organize app reloading code, don't need to restart listen every time.

View file

@ -223,7 +223,7 @@ module Middleman
# messages, which can take a long time (minutes at full CPU)
# if the object is huge or has cyclic references, like this.
def to_s
"#<Middleman::Application>"
"#<Middleman::Application:0x#{object_id}>"
end
# Expand a path to include the index file if it's a directory

View file

@ -21,8 +21,6 @@ module Middleman
mount_instance
logger.info "== The Middleman is standing watch on port #{port}"
start_file_watcher unless @options[:"disable-watcher"]
@initialized ||= false
unless @initialized
@initialized = true
@ -79,37 +77,27 @@ module Middleman
end
def start_file_watcher
return if @options[:"disable-watcher"]
first_run = !@listener
if first_run
# Watcher Library
require "listen"
return if @listener
@listener = Listen.to(Dir.pwd, :relative_paths => true)
end
@listener.change do |modified, added, removed|
added_and_modified = (modified + added)
unless added_and_modified.empty?
# See if the changed file is config.rb or lib/*.rb
if needs_to_reload?(added_and_modified)
if needs_to_reload?(added_and_modified) || needs_to_reload?(removed)
reload
return
end
# Otherwise forward to Middleman
else
added_and_modified.each do |path|
app.files.did_change(path)
end
end
unless removed.empty?
# See if the changed file is config.rb or lib/*.rb
if needs_to_reload?(removed)
reload
return
end
# Otherwise forward to Middleman
removed.each do |path|
app.files.did_delete(path)
end
@ -117,7 +105,7 @@ module Middleman
end
# Don't block this thread
@listener.start(false)
@listener.start(false) if first_run
end
# Trap the interupt signal and shut down smoothly
@ -164,6 +152,7 @@ module Middleman
)
@app = new_app
start_file_watcher
@webrick.mount "/", ::Rack::Handler::WEBrick, app.class.to_rack_app
end