Sha256: 718787cd507ac12d0e7f0689d679b3e577b75336dd0031fa09eeb72cc568f9c5

Contents?: true

Size: 793 Bytes

Versions: 3

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

require 'pathname'

module CleanupVendor
  class Path < ::Pathname
    def recursive_entries
      return to_enum(:recursive_entries) unless block_given?

      glob('**/*', File::FNM_DOTMATCH) do |path|
        yield(Path.new(path)) unless path == self
      end
    end

    def match?(patterns)
      patterns.any? do |p|
        p.eql?(self) ||
          p.start_with?('**') && fnmatch?(p, File::FNM_EXTGLOB) ||
          basename.fnmatch?(p, File::FNM_EXTGLOB) && gem_level?
      end
    end

    def gem_level?
      @gem_level ||= parent.glob('*.gemspec').any?
    end

    def include?(enum)
      descend.any? { |p| enum.include?(p) }
    end

    def summary
      entries = [self] + recursive_entries.to_a
      entries.map(&:stat)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cleanup_vendor-0.6.1 lib/cleanup_vendor/path.rb
cleanup_vendor-0.6.0 lib/cleanup_vendor/path.rb
cleanup_vendor-0.5.0 lib/cleanup_vendor/path.rb