Class: Jasmine::PathExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine/path_expander.rb

Class Method Summary collapse

Class Method Details

.expand(base_directory, patterns, globber = Dir.method(:glob)) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jasmine/path_expander.rb', line 4

def self.expand(base_directory, patterns, globber = Dir.method(:glob))
  negative, positive = patterns.partition {|pattern| /^!/ =~ pattern}
  chosen, negated = [positive, negative].collect do |patterns|
    patterns.map do |path|
      files = globber.call(File.join(base_directory, path.gsub(/^!/, '')))
      if files.empty? && !(path =~ /\*|^\!/)
        if path[0..3] == 'http'
          files << path
        else
          files = [File.join(base_directory, path)]
        end
      end
      files.sort
    end.flatten.uniq
  end
  chosen - negated
end