class PathSearch
Copyright © 2013 Nathan Currier
Use, modification, and distribution are all subject to the Boost Software License, Version 1.0. (See the accompanying file LICENSE.md or at rideliner.tk/LICENSE.html).
<description>
Attributes
defaultExts[RW]
paths[RW]
Public Class Methods
new(paths = [ ])
click to toggle source
# File lib/bakery/detail/search.rb, line 65 def initialize paths = [ ] @paths = paths end
Public Instance Methods
addSearchDirectory(dir)
click to toggle source
# File lib/bakery/detail/search.rb, line 69 def addSearchDirectory dir if File.exist?(dir) && File.directory?(dir) && !@paths.include?(dir) Bakery::Log.debug "directory added to search path: #{dir}" @paths << dir else Bakery::Log.warning "directory not added to search path: #{dir}" end end
search(filename) { |file| ... }
click to toggle source
# File lib/bakery/detail/search.rb, line 40 def search filename if File.exist? filename file = filename end if file == nil file = searchAllPaths File.basename(filename) end if file == nil file = searchWithExts File.basename(filename, File.extname(filename)) end if block_given? if file != nil yield file else Bakery::Log.warning "no results found in search: #{filename}" Bakery::Log.debug "search path: #{paths}" end end file end
Private Instance Methods
searchAllPaths(filename)
click to toggle source
# File lib/bakery/detail/search.rb, line 17 def searchAllPaths filename base = File.basename filename paths.each { |dir| if File.exist?(File.join dir, base) return File.join dir, base end } nil end
searchWithExts(filename)
click to toggle source
# File lib/bakery/detail/search.rb, line 28 def searchWithExts filename defaultExts.each { |ext| file = "#{filename}.#{ext}" found = searchAllPaths file if found != nil return found end } nil end