Sha256: 55685fc03fd0e3c8f5e6057880fe93bdd4fe7ead26f646af9f9cc9d6d1636340

Contents?: true

Size: 879 Bytes

Versions: 56

Compression:

Stored size: 879 Bytes

Contents

class KuberKit::Tools::WorkdirDetector
  include KuberKit::Import[
    "configs",
    "tools.file_presence_checker"
  ]

  def call(options, current_dir: nil)
    current_dir ||= Dir.pwd
    default_dir   = File.join(current_dir, configs.kuber_kit_dirname)
    workdir_path  = options[:path] || ENV['KUBER_KIT_PATH'] || default_dir

    unless file_presence_checker.dir_exists?(workdir_path)
      workdir_in_ancestors = find_workdir_in_ancestors(current_dir)
      workdir_path = workdir_in_ancestors if workdir_in_ancestors
    end

    workdir_path
  end

  private
    def find_workdir_in_ancestors(dir)
      if dir == "/"
        return nil
      end

      workdir_path = File.join(dir, configs.kuber_kit_dirname)
      if file_presence_checker.dir_exists?(workdir_path)
        return workdir_path
      end

      find_workdir_in_ancestors(File.dirname(dir))
    end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
kuber_kit-1.3.9 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.8 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.7 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.1.8 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.6 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.1.7 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.5 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.4 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.1.6 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.3 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.2 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.1.5 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.1 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.3.0 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.1.4 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.2.7 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.2.6 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.2.5 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.2.4 lib/kuber_kit/tools/workdir_detector.rb
kuber_kit-1.2.2 lib/kuber_kit/tools/workdir_detector.rb