Sha256: 5b24402c38974bb2542228944c7d41503b6c1d6294c448e20980a86b545d32f2

Contents?: true

Size: 788 Bytes

Versions: 3

Compression:

Stored size: 788 Bytes

Contents

require 'open3'

module Hobo
  module Helper
    def locate(pattern, opts = {}, &block)
      match = nil

      Dir.chdir Hobo.project_path do
        match = locate_git(pattern, false, &block)
        match = locate_git(pattern, true, &block) if !match
      end

      return true if match

      Hobo.ui.warning opts[:missing] if opts[:missing]
      return false
    end

    private

    def locate_git pattern, others, &block
      args = [ 'git', 'ls-files', pattern ]
      args.push '-o' if others
      output = Hobo::Helper.shell *args, :capture => true
      path = output.split("\n")[0]

      unless path.nil?
        path.strip!
        Dir.chdir File.dirname(path) do
          yield path
        end

        return true
      end
    end
  end
end

include Hobo::Helper

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hobo-inviqa-0.0.4 lib/hobo/helper/file_locator.rb
hobo-inviqa-0.0.3 lib/hobo/helper/file_locator.rb
hobo-inviqa-0.0.2 lib/hobo/helper/file_locator.rb