Sha256: 3ab7e5961105a996b9b49a76022025229926babb1aa90bcbe9044ca07189dcae

Contents?: true

Size: 1.07 KB

Versions: 187

Compression:

Stored size: 1.07 KB

Contents

require "pathname"
require "set"

module CC
  class Workspace
    class PathTree
      autoload :DirNode, "cc/workspace/path_tree/dir_node"
      autoload :FileNode, "cc/workspace/path_tree/file_node"

      def self.node_for_pathname(pathname)
        if pathname.directory?
          DirNode.new(pathname.to_s)
        else
          FileNode.new(pathname.to_s)
        end
      end

      def self.for_path(path)
        new(node_for_pathname(Pathname.new(path)))
      end

      def initialize(root_node)
        @root_node = root_node
      end

      def clone
        self.class.new(root_node.clone)
      end

      def exclude_paths(paths)
        paths.each { |path| root_node.remove(*normalized_path_pieces(path)) }
      end

      def include_paths(paths)
        paths.each { |path| root_node.add(*normalized_path_pieces(path)) }
      end

      delegate :all_paths, to: :root_node

      private

      attr_reader :root_node

      def normalized_path_pieces(path)
        Pathname.new(path).cleanpath.to_s.split(File::SEPARATOR).reject(&:blank?)
      end
    end
  end
end

Version data entries

187 entries across 187 versions & 2 rubygems

Version Path
codeclimate-fede-0.85.38 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.37 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.36 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.35 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.33 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.32 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.31 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.30 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.21 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.24 lib/cc/workspace/path_tree.rb
codeclimate-fede-0.85.23 lib/cc/workspace/path_tree.rb
codeclimate-0.85.23 lib/cc/workspace/path_tree.rb
codeclimate-0.85.22 lib/cc/workspace/path_tree.rb
codeclimate-0.85.21 lib/cc/workspace/path_tree.rb
codeclimate-0.85.19 lib/cc/workspace/path_tree.rb
codeclimate-0.85.18 lib/cc/workspace/path_tree.rb
codeclimate-0.85.17 lib/cc/workspace/path_tree.rb
codeclimate-0.85.15 lib/cc/workspace/path_tree.rb
codeclimate-0.85.14 lib/cc/workspace/path_tree.rb
codeclimate-0.85.13 lib/cc/workspace/path_tree.rb