Sha256: 9f17de16930aa9507d72eda702219b98e514ffa48897ad167bc51f8b8fac1c0e

Contents?: true

Size: 877 Bytes

Versions: 2

Compression:

Stored size: 877 Bytes

Contents

module Soloist
  module Util
    def with_or_without_dot(file_name)
      [file_name, ".#{file_name}"]
    end
    
    def fileify(contents)
      file = Tempfile.new("soloist")
      file << contents
      file.flush
      file
    end
    
    def walk_up_and_find_file(filenames, opts={})
      pwd = FileUtils.pwd
      file = nil
      path_to_file = ""
      while !file && FileUtils.pwd != '/'
        file = filenames.detect { |f| File.exists?(f) }
        FileUtils.cd("..")
        path_to_file << "../" unless file
      end
      FileUtils.cd(pwd)
      if file
        file_contents = File.read(path_to_file + file) if file
        [file_contents, path_to_file]
      elsif opts[:required] == false
        [nil, nil]
      else
        raise Errno::ENOENT, "#{filenames.join(" or ")} not found" unless file || opts[:required] == false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
soloist-0.9.1 lib/soloist/util.rb
soloist-0.9.0 lib/soloist/util.rb