Class: TestBench::Run::SelectFiles
- Inherits:
-
Object
- Object
- TestBench::Run::SelectFiles
show all
- Defined in:
- lib/test_bench/run/select_files.rb,
lib/test_bench/run/select_files/substitute.rb
Defined Under Namespace
Modules: Defaults, Substitute
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#apex_directory ⇒ Object
Returns the value of attribute apex_directory.
9
10
11
|
# File 'lib/test_bench/run/select_files.rb', line 9
def apex_directory
@apex_directory
end
|
#exclude_patterns ⇒ Object
4
5
6
|
# File 'lib/test_bench/run/select_files.rb', line 4
def exclude_patterns
@exclude_patterns ||= []
end
|
Class Method Details
.build(exclude_patterns: nil) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/test_bench/run/select_files.rb', line 11
def self.build(exclude_patterns: nil)
exclude_patterns ||= Defaults.exclude_file_patterns
exclude_patterns = Array(exclude_patterns)
instance = new
instance.exclude_patterns = exclude_patterns
instance
end
|
21
22
23
24
25
26
|
# File 'lib/test_bench/run/select_files.rb', line 21
def self.configure(receiver, exclude_patterns: nil, attr_name: nil)
attr_name ||= :select_files
instance = build(exclude_patterns:)
receiver.public_send(:"#{attr_name}=", instance)
end
|
Instance Method Details
#call(path, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/test_bench/run/select_files.rb', line 28
def call(path, &block)
full_path = ::File.expand_path(path, apex_directory)
if not ::File.exist?(full_path)
block.(path)
return
end
extension = ::File.extname(path)
if extension.empty?
directory_path = path
glob_pattern = ::File.join(directory_path, '**', '*.rb')
else
file_path = path
glob_pattern = file_path
end
Dir.glob(glob_pattern, base: apex_directory) do |file|
excluded = exclude_patterns.any? do |exclude_pattern|
::File.fnmatch?(exclude_pattern, file, ::File::FNM_EXTGLOB)
end
if excluded
next
end
block.(file)
end
end
|