class Soloist::Spotlight

Attributes

pathname[R]

Public Class Methods

find(*file_names) click to toggle source
# File lib/soloist/spotlight.rb, line 9
def self.find(*file_names)
  new(Dir.pwd).find(*file_names)
end
find!(*file_names) click to toggle source
# File lib/soloist/spotlight.rb, line 13
def self.find!(*file_names)
  new(Dir.pwd).find!(*file_names)
end
new(path) click to toggle source
# File lib/soloist/spotlight.rb, line 17
def initialize(path)
  @pathname = Pathname.new(path)
end

Public Instance Methods

find(*file_names) click to toggle source
# File lib/soloist/spotlight.rb, line 21
def find(*file_names)
  pathname.ascend do |path|
    file_name = file_names.detect { |fn| path.join(fn).file? }
    break path.join(file_name) if file_name
  end
end
find!(*file_names) click to toggle source
# File lib/soloist/spotlight.rb, line 28
def find!(*file_names)
  file_path = find(*file_names)
  unless file_path
    file_names = if file_names.length > 2
      file_names[0...-1].join(", ") + " or " + file_names.last
    else
      file_names.join(" or ")
    end
    raise Soloist::NotFound.new("Could not find #{file_names}")
  end
  file_path
end