-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsource_component.rb
More file actions
46 lines (34 loc) · 907 Bytes
/
Copy pathsource_component.rb
File metadata and controls
46 lines (34 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
require 'pathname'
require_relative 'config'
require_relative 'include_dependency'
require_relative 'directory_parser'
require_relative 'source_file'
# Abstracts a source directory containing source files
class SourceComponent
include Config
include DirectoryParser
attr_reader :path
def initialize(path)
@path = path
end
def name
@name ||= File.basename(@path)
end
def source_files
@source_files ||= parse_source_files(source_file_extensions)
end
def includes
@includes ||= source_files.flat_map(&:includes).uniq.map { |f| IncludeDependency.new(f) }.uniq
end
def loc
@loc ||= source_files.inject(0) { |total_loc, file| total_loc + file.loc }
end
def exists?
File.exist?(@path)
end
private
def parse_source_files(extensions)
glob_files(@path, extensions).map { |e| SourceFile.new(e) }.compact
end
end