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.



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

def initialize paths = [ ]
  @paths = paths
end

Instance Attribute Details

#defaultExtsObject

Returns the value of attribute defaultExts.



74
75
76
# File 'lib/bakery/detail/search.rb', line 74

def defaultExts
  @defaultExts
end

#pathsObject

Returns the value of attribute paths.



74
75
76
# File 'lib/bakery/detail/search.rb', line 74

def paths
  @paths
end

Instance Method Details

#addSearchDirectory(dir) ⇒ Object



68
69
70
71
72
# File 'lib/bakery/detail/search.rb', line 68

def addSearchDirectory dir
  if File.exist?(dir) && File.directory?(dir) && !@paths.include?(dir)
    @paths << 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
# 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
      stderr.puts "[WARNING] #{filename} was not found while searching in #{paths}."
    end
  end

  file
end