Class: Soloist::Spotlight
- Inherits:
-
Object
- Object
- Soloist::Spotlight
- Defined in:
- lib/soloist/spotlight.rb
Instance Attribute Summary collapse
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
Class Method Summary collapse
Instance Method Summary collapse
- #find(*file_names) ⇒ Object
- #find!(*file_names) ⇒ Object
-
#initialize(path) ⇒ Spotlight
constructor
A new instance of Spotlight.
Constructor Details
#initialize(path) ⇒ Spotlight
Returns a new instance of Spotlight.
17 18 19 |
# File 'lib/soloist/spotlight.rb', line 17 def initialize(path) @pathname = Pathname.new(path) end |
Instance Attribute Details
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
7 8 9 |
# File 'lib/soloist/spotlight.rb', line 7 def pathname @pathname end |
Class Method Details
.find(*file_names) ⇒ Object
9 10 11 |
# File 'lib/soloist/spotlight.rb', line 9 def self.find(*file_names) new(Dir.pwd).find(*file_names) end |
.find!(*file_names) ⇒ Object
13 14 15 |
# File 'lib/soloist/spotlight.rb', line 13 def self.find!(*file_names) new(Dir.pwd).find!(*file_names) end |
Instance Method Details
#find(*file_names) ⇒ Object
21 22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |