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
# 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 =~ /\*|^\!/)
        files = [File.join(base_directory, path)]
      end
      files
    end.flatten.uniq
  end
  chosen - negated
end