Sha256: fc18e3248f73e98cd9681a95a0d6f60d40b643943af79bfc1c3836d4648b49a4

Contents?: true

Size: 963 Bytes

Versions: 6

Compression:

Stored size: 963 Bytes

Contents

module Massimo
  class Watcher
    class << self
      def start(site)
        self.new(site).run
      end
    end
    
    def initialize(site)
      @site  = site
      @files = []
    end
    
    def run
      loop do
        process
        sleep 0.5
      end
    end
    
    def process
      if changed?
        begin
          puts 'massimo has noticed a change'
          @site.process
          puts 'massimo has built your site'
        rescue Exception => e
          puts e.message
          puts e.backtrace
        end
      end
    end
    
    def changed?
      @files != files
    end
    
    protected
    
      def files
        @files = Dir[*glob].map { |file| File.mtime(file) }
      end
      
      def glob
        glob  = @site.resources.map(&:path)
        glob << @site.config.path_for(:lib)
        glob << @site.config.path_for(:helpers)
        glob.map! { |path| File.join(path, '**/*.*') }
        glob
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
massimo-0.5.5 lib/massimo/watcher.rb
massimo-0.5.4 lib/massimo/watcher.rb
massimo-0.5.3 lib/massimo/watcher.rb
massimo-0.5.2 lib/massimo/watcher.rb
massimo-0.5.1 lib/massimo/watcher.rb
massimo-0.5.0 lib/massimo/watcher.rb