Sha256: b64a813142a9388629930b50d6cfb032bbf4839a2911b4b95b9ace5cf56cd93e

Contents?: true

Size: 878 Bytes

Versions: 8

Compression:

Stored size: 878 Bytes

Contents

module Guard
  class Watcher
    attr_accessor :pattern, :action
    
    def initialize(pattern, action = nil)
      @pattern, @action = pattern, action
    end
    
    def self.match_files(guard, files)
      guard.watchers.inject([]) do |paths, watcher|
        files.each do |file|
          if matches = file.match(watcher.pattern)
            if watcher.action
              begin 
                if watcher.action.arity == 1
                  result = watcher.action.call(matches)
                else
                  result = watcher.action.call
                end
              rescue
                UI.info "Problem with watch action"
              end
              paths << result if result.is_a?(String) && result != ''
            else
              paths << matches[0]
            end
          end
        end
        paths
      end
    end
    
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/guard-0.2.2/lib/guard/watcher.rb
guard-0.2.2 lib/guard/watcher.rb
guard-0.2.1 lib/guard/watcher.rb
guard-0.2.0 lib/guard/watcher.rb
guard-0.2.0.beta.1 lib/guard/watcher.rb
guard-0.1.1 lib/guard/watcher.rb
guard-0.1.0 lib/guard/watcher.rb
guard-0.1.0.beta.2 lib/guard/watcher.rb