Class: PDD::Sources
- Inherits:
-
Object
- Object
- PDD::Sources
- Defined in:
- lib/pdd/sources.rb
Overview
Code base abstraction
Instance Method Summary collapse
- #exclude(paths) ⇒ Object
-
#fetch ⇒ Object
Fetch all sources.
- #include(paths) ⇒ Object
-
#initialize(dir) ⇒ Sources
constructor
Ctor.
Constructor Details
#initialize(dir) ⇒ Sources
Ctor.
dir-
Directory with source code files
15 16 17 18 19 |
# File 'lib/pdd/sources.rb', line 15 def initialize(dir) @dir = File.absolute_path(dir) @exclude = ['.git/**/*'] @include = [] end |
Instance Method Details
#exclude(paths) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/pdd/sources.rb', line 41 def exclude(paths) paths = [] if paths.nil? paths = [paths] unless paths.is_a?(Array) @exclude.push(*paths) paths&.each do |path| PDD.log.info "#{Rainbow('Excluding').orange} #{path}" end self end |
#fetch ⇒ Object
Fetch all sources.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pdd/sources.rb', line 22 def fetch exclude_paths = @exclude.map do |ptn| Glob.new(File.join(@dir, ptn)).to_regexp end files = Dir.glob( File.join(@dir, '**/*'), File::FNM_DOTMATCH ).reject do |f| File.directory?(f) || exclude_paths.any? { |ptn| f.match(ptn) } end files += Dir.glob( @include.map { |ptn| File.join(@dir, ptn) } ).reject { |f| File.directory?(f) } files = files.uniq # remove duplicates files.reject { |f| binary?(f) }.map do |file| path = file[@dir.length + 1, file.length] VerboseSource.new(path, Source.new(file, path)) end end |