Sha256: edd097ac27988ce242d7fa2c79dab5c3df8652c1a5f74a6e96ca8f96164576d7

Contents?: true

Size: 669 Bytes

Versions: 3

Compression:

Stored size: 669 Bytes

Contents

# encoding: UTF-8

module Bunch
  class Ignorer
    PATTERNS = [
      /^\.DS_Store$/,
      /^.*~$/,
      /^#.*\#$/ #/(comment fixes broken vim highlighting)
    ]

    def initialize(tree)
      @input  = tree
      @output = FileTree.new
    end

    def result
      @path = []
      @input.accept(self)
      @output
    end

    def enter_tree(tree)
      @path << tree.name if tree.name
    end

    def leave_tree(tree)
      @path.pop if tree.name
    end

    def visit_file(file)
      file_path = [*@path, file.path].join("/")

      unless PATTERNS.any? { |p| p.match(file.path) }
        @output.write file_path, file.content
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bunch-1.0.0pre3 lib/bunch/ignorer.rb
bunch-1.0.0pre2 lib/bunch/ignorer.rb
bunch-1.0.0pre1 lib/bunch/ignorer.rb