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

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