Class: SourceFinder::SourceFileGlobber

Inherits:
Object
  • Object
show all
Includes:
GroovySourceFileGlobber, JsSourceFileGlobber, PythonSourceFileGlobber, RubySourceFileGlobber
Defined in:
lib/source_finder/source_file_globber.rb

Overview

Give configuration, finds source file locations by using an inclusion and exclusion glob

Instance Attribute Summary collapse

Attributes included from GroovySourceFileGlobber

#extra_groovy_files_arr, #groovy_dirs_arr, #groovy_file_extensions_arr

Attributes included from PythonSourceFileGlobber

#extra_python_files_arr, #python_dirs_arr, #python_file_extensions_arr

Attributes included from JsSourceFileGlobber

#extra_js_files_arr, #js_dirs_arr, #js_file_extensions_arr

Attributes included from RubySourceFileGlobber

#extra_ruby_files_arr, #ruby_dirs_arr, #ruby_file_extensions_arr

Instance Method Summary collapse

Methods included from GroovySourceFileGlobber

#groovy_file_extensions_glob, #groovy_files_arr, #groovy_files_glob

Methods included from PythonSourceFileGlobber

#python_file_extensions_glob, #python_files_arr, #python_files_glob

Methods included from JsSourceFileGlobber

#js_file_extensions_glob, #js_files_arr, #js_files_glob

Methods included from RubySourceFileGlobber

#ruby_file_extensions_glob, #ruby_files_arr, #ruby_files_glob

Constructor Details

#initialize(globber: Dir) ⇒ SourceFileGlobber

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_arrObject



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

#extra_source_files_arrObject



32
33
34
35
36
37
# File 'lib/source_finder/source_file_globber.rb', line 32

def extra_source_files_arr
  @extra_source_files_arr ||=
    (extra_ruby_files_arr + extra_js_files_arr +
     extra_python_files_arr + extra_groovy_files_arr)
    .concat(%w(Dockerfile)).sort.uniq
end

#source_dirs_arrObject



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_arrObject



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_globObject



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_globObject



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(extra_source_files_arr, 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_arrObject



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_globObject



39
40
41
# File 'lib/source_finder/source_file_globber.rb', line 39

def default_source_files_exclude_glob
  '**/vendor/**'
end

#doc_file_extensions_arrObject



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

Returns:

  • (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(extra_source_files_arr, dirs_arr, extensions_glob)
  '{' + arr2glob(extra_source_files_arr) + "{*,.*}.{#{extensions_glob}}," +
    File.join("{#{dirs_arr.join(',')}}", '**',
              "{*,.*}.{#{extensions_glob}}") + '}'
end

#source_and_doc_file_extensions_arrObject



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_globObject



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_globObject



95
96
97
98
# File 'lib/source_finder/source_file_globber.rb', line 95

def source_and_doc_files_glob
  make_files_glob(extra_source_files_arr, source_dirs_arr,
                  source_and_doc_file_extensions_glob)
end

#source_file_extensions_globObject



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_arrObject



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