lib/guard/rails-assets.rb in guard-rails-assets-0.0.4 vs lib/guard/rails-assets.rb in guard-rails-assets-0.0.5

- old
+ new

@@ -4,17 +4,21 @@ module Guard class RailsAssets < Guard def initialize(watchers=[], options={}) super @options = options || {} + @run_on = @options[:run_on] || [:start, :change] + @run_on = [@run_on] unless @run_on.respond_to?(:include?) end def start + runner.start if runner.respond_to? :start compile_assets if run_for? :start end def reload + runner.reload if runner.respond_to? :reload compile_assets if run_for? :reload end def run_all compile_assets if run_for? :all @@ -23,22 +27,32 @@ def run_on_change(paths=[]) compile_assets if run_for? :change end def compile_assets - puts 'Compiling rails assets' - result = system "bundle exec rake assets:clean assets:precompile" + puts "Compiling rails assets with #{runner.class.name}." + result = runner.compile_assets + if result Notifier::notify 'Assets compiled' + puts 'Assets compiled.' else Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed + puts 'Failed to compile assets.' end end + def runner + @runner ||= begin + runner_name = (@options[:runner] || :rails).to_s + + require_relative "rails-assets/#{runner_name}_runner" + ::Guard::RailsAssets.const_get(runner_name.capitalize + 'Runner').new(@options) + end + end + def run_for? command - run_on = @options[:run_on] - 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) + @run_on.include?(command) end end end +