Sha256: 7a246248d54572b225bb37f8977452aee1d8081429ce3b7f4fa6024813151c1c

Contents?: true

Size: 863 Bytes

Versions: 4

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Core
    class PathTraversal
      attr_reader :root

      def initialize(root, recursive: true)
        @root = root
        @recursive = recursive
      end

      def each(&block)
        each_file_in(root, &block)
      end

      def to_enum
        Enumerator.new do |yielder|
          each do |item|
            yielder.yield item
          end
        end
      end

      private

      def recursive?
        @recursive
      end

      def each_file_in(dir, &block)
        files = File.directory?(dir) ? Dir.glob(File.join(dir, '*')) : [dir]
        files.each do |file|
          if File.directory?(file)
            each_file_in(file, &block) if recursive?
          else
            Spandx.logger.debug(file)
            block.call(file)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spandx-0.13.3 lib/spandx/core/path_traversal.rb
spandx-0.13.2 lib/spandx/core/path_traversal.rb
spandx-0.13.1 lib/spandx/core/path_traversal.rb
spandx-0.13.0 lib/spandx/core/path_traversal.rb