Class: TestBench::ExpandPath

Inherits:
Object
  • Object
show all
Defined in:
lib/test_bench/expand_path.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_directory, exclude_pattern, dir) ⇒ ExpandPath



7
8
9
10
11
# File 'lib/test_bench/expand_path.rb', line 7

def initialize root_directory, exclude_pattern, dir
  @dir = dir
  @exclude_pattern = exclude_pattern
  @root_directory = root_directory
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



3
4
5
# File 'lib/test_bench/expand_path.rb', line 3

def dir
  @dir
end

#exclude_patternObject (readonly)

Returns the value of attribute exclude_pattern.



4
5
6
# File 'lib/test_bench/expand_path.rb', line 4

def exclude_pattern
  @exclude_pattern
end

#root_directoryObject (readonly)

Returns the value of attribute root_directory.



5
6
7
# File 'lib/test_bench/expand_path.rb', line 5

def root_directory
  @root_directory
end

Class Method Details

.build(root_directory, exclude_pattern = nil, dir: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/test_bench/expand_path.rb', line 13

def self.build root_directory, exclude_pattern=nil, dir: nil
  dir ||= Dir

  exclude_pattern ||= Settings.toplevel.exclude_pattern
  exclude_pattern = Regexp.new exclude_pattern if exclude_pattern.is_a? String

  root_directory = Pathname root_directory

  new root_directory, exclude_pattern, dir
end

Instance Method Details

#call(pattern) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/test_bench/expand_path.rb', line 24

def call pattern
  full_pattern = root_directory.join pattern

  if dir.exist? full_pattern
    full_pattern = full_pattern.join '**/*.rb'
  end

  expand full_pattern.to_s
end

#expand(full_pattern) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/test_bench/expand_path.rb', line 34

def expand full_pattern
  dir[full_pattern].flat_map do |file|
    if exclude_pattern.match file
      []
    else
      [file]
    end
  end
end