class TestBench::ExpandPath

Attributes

dir[R]
exclude_pattern[R]
root_directory[R]

Public Class Methods

build(root_directory, exclude_pattern=nil, dir: nil) click to toggle source
# 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
new(root_directory, exclude_pattern, dir) click to toggle source
# 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

Public Instance Methods

call(pattern) click to toggle source
# 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) click to toggle source
# 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