Sha256: dbf903db745f4319b29d3fc53e9e33fbe85f9e676b4e66b04ef53d89d734bed2

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 KB

Contents

module CC
  module Analyzer
    class PathFilter
      attr_reader :paths

      def initialize(paths)
        @paths = paths
      end

      def reject_unreadable_paths
        @paths = paths - unreadable_path_entries
        self
      end

      def reject_paths(ignore_paths)
        @paths = paths - ignore_paths
        self
      end

      def select_readable_files
        @paths = paths.select { |path| File.exist?(path) && FileUtils.readable_by_all?(path) }
        self
      end

      def reject_symlinks
        @paths = paths.reject { |path| File.symlink?(path) }
        self
      end

      def reject_globs(globs)
        patterns = PathPatterns.new(globs)
        @paths = paths.reject { |path| patterns.match?(pathpatterns.match?(path)) }
        self
      end

      private

      def unreadable_path_entries
        @_unreadable_path_entries ||=
          unreadable_paths.flat_map { |path| PathEntries.new(path).entries }
      end

      def unreadable_paths
        paths.select do |path|
          File.directory?(path) && !FileUtils.readable_by_all?(path)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
codeclimate-0.17.0 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.6 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.5 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.4 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.3 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.2 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.1 lib/cc/analyzer/path_filter.rb
codeclimate-0.16.0 lib/cc/analyzer/path_filter.rb
codeclimate-0.15.2 lib/cc/analyzer/path_filter.rb
codeclimate-0.15.1 lib/cc/analyzer/path_filter.rb
codeclimate-0.15.0 lib/cc/analyzer/path_filter.rb
codeclimate-0.14.7 lib/cc/analyzer/path_filter.rb
codeclimate-0.14.6 lib/cc/analyzer/path_filter.rb
codeclimate-0.14.5 lib/cc/analyzer/path_filter.rb
codeclimate-0.14.4 lib/cc/analyzer/path_filter.rb