-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Rails 3.2+ class reloading when available
Additional custom_reloaders can also be passed in via options to support other frameworks like Rails 2.x or custom class reloaders. Closes #29
- Loading branch information
Showing
4 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Reloaders | ||
def initialize | ||
@reloaders = [] | ||
end | ||
|
||
# Add a reloader to be called on reload | ||
def register(options = {}, &block) | ||
if options[:prepend] | ||
@reloaders.unshift block | ||
else | ||
@reloaders << block | ||
end | ||
end | ||
|
||
def reload(paths = []) | ||
@reloaders.each do |reloader| | ||
reloader.call(paths) | ||
end | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
describe Reloaders do | ||
subject(:reloaders) { described_class.new } | ||
|
||
describe 'storing blocks to be executed at reload time' do | ||
it 'passes the paths to be reloaded to the reloaders' do | ||
reloaders.register do |paths| | ||
paths.should == ['/path/to/file'] | ||
end | ||
reloaders.reload ['/path/to/file'] | ||
end | ||
|
||
describe 'the order in which reloaders are executed' do | ||
before :each do | ||
@a = @b = @counter = 0 | ||
reloaders.register do | ||
@counter += 1 | ||
@a = @counter | ||
end | ||
reloaders.register(:prepend => prepend) do | ||
@counter += 1 | ||
@b = @counter | ||
end | ||
reloaders.reload | ||
end | ||
|
||
context 'in normal order' do | ||
let(:prepend) { false } | ||
it 'reloads in the same order as reloaders registered' do | ||
@a.should == 1 | ||
@b.should == 2 | ||
end | ||
end | ||
|
||
context 'with the 2nd reloader prepended' do | ||
let(:prepend) { true } | ||
it 'reloads in the same order as reloaders registered' do | ||
@a.should == 2 | ||
@b.should == 1 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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 characters