Class: CSSPushServer
- Inherits:
-
Object
- Object
- CSSPushServer
- Defined in:
- lib/css_push_server.rb
Instance Attribute Summary collapse
-
#directories ⇒ Object
Returns the value of attribute directories.
-
#last_mtime ⇒ Object
Returns the value of attribute last_mtime.
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast_changes(files) ⇒ Object
- #find_files ⇒ Object
- #find_files_to_broadcast ⇒ Object
-
#initialize ⇒ CSSPushServer
constructor
A new instance of CSSPushServer.
- #run ⇒ Object
- #wait_for_changes ⇒ Object
Constructor Details
#initialize ⇒ CSSPushServer
Returns a new instance of CSSPushServer.
13 14 15 16 17 18 |
# File 'lib/css_push_server.rb', line 13 def initialize css_root = File.join(ROOT, "public", "stylesheets") self.directories = [css_root] self.last_mtime = Time.now end |
Instance Attribute Details
#directories ⇒ Object
Returns the value of attribute directories.
11 12 13 |
# File 'lib/css_push_server.rb', line 11 def directories @directories end |
#last_mtime ⇒ Object
Returns the value of attribute last_mtime.
11 12 13 |
# File 'lib/css_push_server.rb', line 11 def last_mtime @last_mtime end |
Class Method Details
.run ⇒ Object
7 8 9 |
# File 'lib/css_push_server.rb', line 7 def self.run self.new.run end |
Instance Method Details
#broadcast_changes(files) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/css_push_server.rb', line 38 def broadcast_changes(files) puts "\n\nBroadcasting updates for: \n" puts files.values.map{|d| d[:rio_name]}.join(", ") Juggernaut.send_to_all("CSSPush.touch([#{ files.values.map{|d| "'" + d[:rio_name] + "'"}.join(", ") }])") end |
#find_files ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/css_push_server.rb', line 57 def find_files result = {} targets = self.directories # from ZenTest targets.each do |target| Find.find(target) do |f| next if test ?d, f next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files next if f =~ /(\.svn)/ # svn files next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files next if f =~ /\.DS_Store/ # OSX metadata filename = f.sub(/^\.\//, '') rio_name = Regexp.new("^#{Regexp.escape(target)}(.*)").match(filename)[1] result[filename] = { :mtime => File.stat(filename).mtime, :rio_name => rio_name } rescue next end end return result end |
#find_files_to_broadcast ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/css_push_server.rb', line 49 def find_files_to_broadcast files = find_files files.each do |filename, data| files.delete(filename) unless self.last_mtime < data[:mtime] end files end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/css_push_server.rb', line 20 def run if (!Juggernaut) puts "Juggernaut needs to be running for autospec to work" return end begin loop do wait_for_changes files = find_files_to_broadcast self.last_mtime = files.values.map {|d| d[:mtime] }.max broadcast_changes(files) end rescue Interrupt puts # Quit with ^C end end |
#wait_for_changes ⇒ Object
45 46 47 |
# File 'lib/css_push_server.rb', line 45 def wait_for_changes Kernel.sleep 1 until !find_files_to_broadcast.empty? end |