Class: Pushify::Server
- Inherits:
-
Object
- Object
- Pushify::Server
- Defined in:
- lib/pushify/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 ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #wait_for_changes ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
14 15 16 17 18 19 20 21 22 |
# File 'lib/pushify/server.rb', line 14 def initialize self.directories = [ File.join(ROOT, "public", "stylesheets"), File.join(ROOT, "public", "images"), File.join(ROOT, "public", "javascripts"), File.join(ROOT, "app", "stylesheets") ] self.last_mtime = Time.now end |
Instance Attribute Details
#directories ⇒ Object
Returns the value of attribute directories.
12 13 14 |
# File 'lib/pushify/server.rb', line 12 def directories @directories end |
#last_mtime ⇒ Object
Returns the value of attribute last_mtime.
12 13 14 |
# File 'lib/pushify/server.rb', line 12 def last_mtime @last_mtime end |
Class Method Details
.run ⇒ Object
8 9 10 |
# File 'lib/pushify/server.rb', line 8 def self.run self.new.run end |
Instance Method Details
#broadcast_changes(files) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/pushify/server.rb', line 42 def broadcast_changes(files) puts "\n\nBroadcasting updates for: \n" puts files.values.map{|d| d[:rio_name]}.join(", ") Pushify::Juggernaut.send_to_all("Pushify.touch([#{ files.values.map{|d| "'" + d[:rio_name] + "'"}.join(", ") }])") end |
#find_files ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pushify/server.rb', line 61 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
53 54 55 56 57 58 59 |
# File 'lib/pushify/server.rb', line 53 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pushify/server.rb', line 24 def run if (!Pushify::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
49 50 51 |
# File 'lib/pushify/server.rb', line 49 def wait_for_changes Kernel.sleep 1 until !find_files_to_broadcast.empty? end |