enable the reloader in subclasses automatically
This commit is contained in:
parent
580ecfeff7
commit
e78f84e1b8
|
@ -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
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue