Class: PathSearch

Inherits:
Object show all
Defined in:
lib/bakery/detail/search.rb

Overview

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>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = [ ]) ⇒ PathSearch

Returns a new instance of PathSearch.



65
66
67
# File 'lib/bakery/detail/search.rb', line 65

def initialize paths = [ ]
  @paths = paths
end

Instance Attribute Details

#defaultExtsObject

Returns the value of attribute defaultExts.



79
80
81
# File 'lib/bakery/detail/search.rb', line 79

def defaultExts
  @defaultExts
end

#pathsObject

Returns the value of attribute paths.



79
80
81
# File 'lib/bakery/detail/search.rb', line 79

def paths
  @paths
end

Instance Method Details

#addSearchDirectory(dir) ⇒ Object



69
70
71
72
73
74
75
76
77
# 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) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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