Cleanup
This commit is contained in:
parent
431daf19a0
commit
b97bb6c144
@ -7,24 +7,17 @@ module Guard
|
|||||||
def initialize(watchers=[], options={})
|
def initialize(watchers=[], options={})
|
||||||
super
|
super
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
end
|
@run_on = @options[:run_on] || [:start, :change]
|
||||||
|
@run_on = [@run_on] unless @run_on.respond_to?(:include?)
|
||||||
def create_rails_runner
|
|
||||||
@rails_runner = RailsRunner.new
|
@rails_runner = RailsRunner.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def rails_runner
|
|
||||||
@rails_runner ||= create_rails_runner
|
|
||||||
end
|
|
||||||
|
|
||||||
def start
|
def start
|
||||||
create_rails_runner
|
|
||||||
|
|
||||||
compile_assets if run_for? :start
|
compile_assets if run_for? :start
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
def reload
|
||||||
rails_runner.restart_rails
|
@rails_runner.restart_rails
|
||||||
|
|
||||||
compile_assets if run_for? :reload
|
compile_assets if run_for? :reload
|
||||||
end
|
end
|
||||||
@ -39,7 +32,7 @@ module Guard
|
|||||||
|
|
||||||
def compile_assets
|
def compile_assets
|
||||||
puts 'Compiling rails assets'
|
puts 'Compiling rails assets'
|
||||||
result = rails_runner.compile_assets
|
result = @rails_runner.compile_assets
|
||||||
|
|
||||||
if result
|
if result
|
||||||
Notifier::notify 'Assets compiled'
|
Notifier::notify 'Assets compiled'
|
||||||
@ -49,10 +42,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run_for? command
|
def run_for? command
|
||||||
run_on = @options[:run_on]
|
@run_on.include?(command)
|
||||||
run_on = [:start, :change] if not run_on or run_on.to_s.empty?
|
|
||||||
run_on = [run_on] unless run_on.respond_to?(:include?)
|
|
||||||
run_on.include?(command)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
module Guard
|
module Guard
|
||||||
|
|
||||||
# Keeps rails loaded in a thread waiting to run the asset pipeline compiler
|
|
||||||
class RailsAssets::RailsRunner
|
class RailsAssets::RailsRunner
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@ -29,6 +28,10 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def boot_rails
|
||||||
|
require "#{Dir.pwd}/config/environment.rb"
|
||||||
|
end
|
||||||
|
|
||||||
def run_compiler
|
def run_compiler
|
||||||
begin
|
begin
|
||||||
@failed = false
|
@failed = false
|
||||||
@ -40,10 +43,6 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot_rails
|
|
||||||
require "#{Dir.pwd}/config/environment.rb"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Runs the asset pipeline compiler.
|
# Runs the asset pipeline compiler.
|
||||||
#
|
#
|
||||||
# @return [ Boolean ] Whether the compilation was successful or not
|
# @return [ Boolean ] Whether the compilation was successful or not
|
||||||
|
@ -3,12 +3,12 @@ require 'guard/rails-assets'
|
|||||||
|
|
||||||
describe Guard::RailsAssets do
|
describe Guard::RailsAssets do
|
||||||
let(:options) { {} }
|
let(:options) { {} }
|
||||||
let(:rails_thread) { mock(Guard::RailsAssets::RailsThread) }
|
let(:rails_runner) { mock(Guard::RailsAssets::RailsRunner) }
|
||||||
subject { Guard::RailsAssets.new(['watchers'], options) }
|
subject { Guard::RailsAssets.new(['watchers'], options) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Guard::RailsAssets::RailsThread.stub(:new => rails_thread)
|
Guard::RailsAssets::RailsRunner.stub(:new => rails_runner)
|
||||||
rails_thread.stub(:compile_assets => true, :restart_rails => true)
|
rails_runner.stub(:compile_assets => true, :restart_rails => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#start' do
|
describe '#start' do
|
||||||
@ -43,7 +43,7 @@ describe Guard::RailsAssets do
|
|||||||
|
|
||||||
describe 'asset compilation using CLI' do
|
describe 'asset compilation using CLI' do
|
||||||
def stub_system_with result
|
def stub_system_with result
|
||||||
rails_thread.should_receive(:compile_assets).and_return result
|
rails_runner.should_receive(:compile_assets).and_return result
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should notify on success' do
|
it 'should notify on success' do
|
||||||
|
Loading…
Reference in New Issue
Block a user