Sha256: 662f607b187db3d6944517e29c9e92d7be4700925cf0230f1cc1b71d2f8c3f2d

Contents?: true

Size: 806 Bytes

Versions: 4

Compression:

Stored size: 806 Bytes

Contents

require 'prj/fast_traverse'

module Prj

  class Finder
    def initialize(projects_root, options = {})
      @root = File.expand_path(projects_root)
      @vcs_directories = Array(options[:vcs_directories])
      @search_nested_repositories = !!options[:search_nested_repositories]
      @result = []
    end

    def find_project_directories
      return @result unless @result.empty?
      FastTraverse.traverse(@root, @search_nested_repositories) do |parent_path, child_name|
        next false unless vcs_directory?(child_name)
        @result << normalize_path(parent_path)
      end
      @result
    end

    private

    def vcs_directory?(directory_name)
      @vcs_directories.include? directory_name
    end

    def normalize_path(path)
      path.sub(@root, "").chomp("/")
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prj-2.0.1 lib/prj/finder.rb
prj-2.0.1.pre.2 lib/prj/finder.rb
prj-2.0.1.pre.1 lib/prj/finder.rb
prj-2.0.0 lib/prj/finder.rb