enable the reloader in subclasses automatically

This commit is contained in:
Gabriel Andretta 2011-06-18 20:22:07 -03:00
parent 580ecfeff7
commit e78f84e1b8
3 changed files with 35 additions and 1 deletions

View File

@ -218,6 +218,14 @@ module Sinatra
stop_registering_extension
result
end
# Does everything Sinatra::Base#register does and then registers
# the reloader in the +subclass+.
def inherited(subclass)
result = super
subclass.register Sinatra::Reloader
result
end
end
# Contains the methods that the extension adds to the Sinatra

View File

@ -1,6 +1,8 @@
class <%= name %> < Sinatra::Base
class <%= name %> < <%= parent %>
<% if enable_reloader %>
register Sinatra::Reloader
enable :reloader
<% end %>
<% unless inline_templates.nil? %>
enable :inline_templates
<% end %>

View File

@ -44,6 +44,8 @@ describe Sinatra::Reloader do
options[:middlewares] ||= []
options[:filters] ||= []
options[:name] ||= app_name
options[:enable_reloader] = true unless options[:enable_reloader] === false
options[:parent] ||= 'Sinatra::Base'
update_file(app_file_path) do |f|
template_path = File.expand_path('../reloader/app.rb.erb', __FILE__)
@ -387,4 +389,26 @@ describe Sinatra::Reloader do
get('/foo').body.strip.should == 'foo'
end
end
it "automatically registers the reloader in the subclases" do
class ::Parent < Sinatra::Base
register Sinatra::Reloader
enable :reloader
end
setup_example_app(
:routes => ['get("/foo") { "foo" }'],
:enable_reloader => false,
:parent => 'Parent'
)
update_app_file(
:routes => ['get("/foo") { "bar" }'],
:enable_reloader => false,
:parent => 'Parent'
)
get('/foo').body.should == 'bar'
end
end