class MindfulWatcher
Public Class Methods
new(args=[])
click to toggle source
# File lib/mindful_watcher.rb, line 3 def initialize(args=[]) puts "initializing sass_watcher" args.delete_if { |a| a == '--watch' } @args = args path_args = args.select { |a| a =~ /.+\:.+/ }.first || "" sources = path_args.gsub(/\:.+/, ' ') @dir2observe = File.realdirpath(File.dirname(sources)) if sources raise NotObservableException, :msg => 'cannot find folder in arguments' if @dir2observe.nil? end
Public Instance Methods
observe_folder()
click to toggle source
# File lib/mindful_watcher.rb, line 14 def observe_folder fm = DirectoryRunner.new(@dir2observe) while true do fm.process do |filename| if @last_change.nil? || File.mtime(filename).to_s > @last_change.to_s @last_change = Time.now update_files(filename) end end sleep 2 end end
update_files(filename)
click to toggle source
# File lib/mindful_watcher.rb, line 27 def update_files(filename) files_converted = system("sass #{@args.join(' ')}") if files_converted puts "#{@last_change} file changed: #{filename}" else raise "SassNotFoundException", :msg => "please run 'gem install sass'" end end