Module: Soloist::Util
- Defined in:
- lib/soloist/util.rb
Instance Method Summary collapse
- #fileify(contents) ⇒ Object
- #walk_up_and_find_file(filenames, opts = {}) ⇒ Object
- #with_or_without_dot(file_name) ⇒ Object
Instance Method Details
#fileify(contents) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/soloist/util.rb', line 7 def fileify(contents) file = Tempfile.new("soloist") file << contents file.flush file end |
#walk_up_and_find_file(filenames, opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/soloist/util.rb', line 14 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 |
#with_or_without_dot(file_name) ⇒ Object
3 4 5 |
# File 'lib/soloist/util.rb', line 3 def with_or_without_dot(file_name) [file_name, ".#{file_name}"] end |