Class: Compass::Commands::WatchProject
- Inherits:
-
UpdateProject
- Object
- Base
- ProjectBase
- UpdateProject
- Compass::Commands::WatchProject
- Defined in:
- lib/compass/commands/watch_project.rb
Instance Attribute Summary collapse
-
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
Attributes inherited from ProjectBase
Attributes inherited from Base
Attributes included from Actions
Instance Method Summary collapse
Methods inherited from UpdateProject
Methods inherited from ProjectBase
Methods inherited from Base
Methods included from Actions
#basename, #compile, #copy, #directory, #relativize, #separate, #strip_trailing_separator, #write_file
Constructor Details
This class inherits a constructor from Compass::Commands::UpdateProject
Instance Attribute Details
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
12 13 14 |
# File 'lib/compass/commands/watch_project.rb', line 12 def last_update_time @last_update_time end |
Instance Method Details
#most_recent_update_time ⇒ Object
40 41 42 |
# File 'lib/compass/commands/watch_project.rb', line 40 def most_recent_update_time Dir.glob(separate("#{project_src_directory}/**/*.sass")).map {|sass_file| File.stat(sass_file).mtime}.max end |
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/compass/commands/watch_project.rb', line 14 def perform puts ">>> Compiling all stylesheets." super self.last_update_time = most_recent_update_time puts ">>> Compass is now watching for changes. Press Ctrl-C to Stop." loop do # TODO: Make this efficient by using filesystem monitoring. begin sleep 1 rescue Interrupt puts "" exit 0 end file, t = should_update? if t begin puts ">>> Change detected to: #{file}" super rescue StandardError => e ::Compass::Exec.report_error(e, ) end self.last_update_time = t end end end |
#should_update? ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/compass/commands/watch_project.rb', line 44 def should_update? t = most_recent_update_time if t > last_update_time file = Dir.glob(separate("#{project_src_directory}/**/*.sass")).detect {|sass_file| File.stat(sass_file).mtime >= t} [file, t] end end |