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
32 33 34 35 36 |
# File 'lib/pdd/sources.rb', line 32 def initialize(dir) @dir = File.absolute_path(dir) @exclude = ['.git/**/*'] @include = [] end |
Instance Method Details
#exclude(paths) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/pdd/sources.rb', line 58 def exclude(paths) paths = paths.nil? ? [] : paths paths = paths.is_a?(Array) ? paths : [paths] @exclude.push(*paths) paths&.each do |path| PDD.log.info "#{Rainbow('Excluding').orange} #{path}" end self end |
#fetch ⇒ Object
Fetch all sources.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pdd/sources.rb', line 39 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 |