Class: SourceFinder::SourceFileGlobber
Overview
Give configuration, finds source file locations by using an
inclusion and exclusion glob
Instance Attribute Summary collapse
#extra_groovy_files_arr, #groovy_dirs_arr, #groovy_file_extensions_arr
#extra_python_files_arr, #python_dirs_arr, #python_file_extensions_arr
#extra_js_files_arr, #js_dirs_arr, #js_file_extensions_arr
#extra_ruby_files_arr, #ruby_dirs_arr, #ruby_file_extensions_arr
Instance Method Summary
collapse
#groovy_file_extensions_glob, #groovy_files_arr, #groovy_files_glob
#python_file_extensions_glob, #python_files_arr, #python_files_glob
#js_file_extensions_glob, #js_files_arr, #js_files_glob
#ruby_file_extensions_glob, #ruby_files_arr, #ruby_files_glob
Constructor Details
Returns a new instance of SourceFileGlobber.
20
21
22
23
24
25
|
# File 'lib/source_finder/source_file_globber.rb', line 20
def initialize(globber: Dir)
@globber = globber
@exclude_files_arr = nil
@source_files_exclude_glob = nil
@exclude_files_arr = nil
end
|
Instance Attribute Details
#exclude_files_arr ⇒ Object
43
44
45
46
47
|
# File 'lib/source_finder/source_file_globber.rb', line 43
def exclude_files_arr
return @exclude_files_arr if @exclude_files_arr
exclude_garbage(@globber.glob(source_files_exclude_glob))
end
|
32
33
34
35
36
37
|
# File 'lib/source_finder/source_file_globber.rb', line 32
def
@extra_source_files_arr ||=
( + +
+ )
.concat(%w(Dockerfile)).sort.uniq
end
|
#source_dirs_arr ⇒ Object
27
28
29
30
|
# File 'lib/source_finder/source_file_globber.rb', line 27
def source_dirs_arr
@source_dirs_arr ||= (ruby_dirs_arr + js_dirs_arr +
python_dirs_arr + groovy_dirs_arr).sort.uniq
end
|
#source_file_extensions_arr ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/source_finder/source_file_globber.rb', line 63
def source_file_extensions_arr
@source_file_extensions_arr ||=
exclude_garbage((ruby_file_extensions_arr +
js_file_extensions_arr +
python_file_extensions_arr +
groovy_file_extensions_arr +
default_source_file_extensions_arr))
end
|
#source_files_exclude_glob ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/source_finder/source_file_globber.rb', line 49
def source_files_exclude_glob
if @exclude_files_arr
"{#{exclude_files_arr.join(',')}}"
elsif @source_files_exclude_glob
@source_files_exclude_glob
else
default_source_files_exclude_glob
end
end
|
#source_files_glob ⇒ Object
88
89
90
91
92
93
|
# File 'lib/source_finder/source_file_globber.rb', line 88
def source_files_glob
glob = @source_files_glob if defined? @source_files_glob
glob ||
make_files_glob(, source_dirs_arr,
source_file_extensions_glob)
end
|
Instance Method Details
#arr2glob(arr) ⇒ Object
100
101
102
|
# File 'lib/source_finder/source_file_globber.rb', line 100
def arr2glob(arr)
!arr.empty? ? "#{arr.join(',')}," : ''
end
|
#default_source_file_extensions_arr ⇒ Object
59
60
61
|
# File 'lib/source_finder/source_file_globber.rb', line 59
def default_source_file_extensions_arr
%w(swift cpp c html java py clj cljs scala yml sh json)
end
|
#default_source_files_exclude_glob ⇒ Object
39
40
41
|
# File 'lib/source_finder/source_file_globber.rb', line 39
def default_source_files_exclude_glob
'**/vendor/**'
end
|
#doc_file_extensions_arr ⇒ Object
72
73
74
|
# File 'lib/source_finder/source_file_globber.rb', line 72
def doc_file_extensions_arr
@doc_file_extensions_arr ||= %w(md)
end
|
#emacs_lockfile?(filename) ⇒ Boolean
114
115
116
|
# File 'lib/source_finder/source_file_globber.rb', line 114
def emacs_lockfile?(filename)
File.basename(filename) =~ /^\.#/
end
|
#exclude_garbage(files_arr) ⇒ Object
118
119
120
|
# File 'lib/source_finder/source_file_globber.rb', line 118
def exclude_garbage(files_arr)
files_arr.reject { |filename| emacs_lockfile?(filename) }.sort.uniq
end
|
#make_extensions_arr(arr_var, default_arr) ⇒ Object
110
111
112
|
# File 'lib/source_finder/source_file_globber.rb', line 110
def make_extensions_arr(arr_var, default_arr)
arr_var || default_arr
end
|
#make_files_glob(extra_source_files_arr, dirs_arr, extensions_glob) ⇒ Object
104
105
106
107
108
|
# File 'lib/source_finder/source_file_globber.rb', line 104
def make_files_glob(, dirs_arr, extensions_glob)
'{' + arr2glob() + "{*,.*}.{#{extensions_glob}}," +
File.join("{#{dirs_arr.join(',')}}", '**',
"{*,.*}.{#{extensions_glob}}") + '}'
end
|
#source_and_doc_file_extensions_arr ⇒ Object
80
81
82
|
# File 'lib/source_finder/source_file_globber.rb', line 80
def source_and_doc_file_extensions_arr
exclude_garbage(doc_file_extensions_arr + source_file_extensions_arr)
end
|
#source_and_doc_file_extensions_glob ⇒ Object
84
85
86
|
# File 'lib/source_finder/source_file_globber.rb', line 84
def source_and_doc_file_extensions_glob
source_and_doc_file_extensions_arr.join(',')
end
|
#source_and_doc_files_glob ⇒ Object
95
96
97
98
|
# File 'lib/source_finder/source_file_globber.rb', line 95
def source_and_doc_files_glob
make_files_glob(, source_dirs_arr,
source_and_doc_file_extensions_glob)
end
|
#source_file_extensions_glob ⇒ Object
76
77
78
|
# File 'lib/source_finder/source_file_globber.rb', line 76
def source_file_extensions_glob
source_file_extensions_arr.join(',')
end
|
#source_files_arr ⇒ Object
122
123
124
|
# File 'lib/source_finder/source_file_globber.rb', line 122
def source_files_arr
exclude_garbage(@globber.glob(source_files_glob) - exclude_files_arr)
end
|