Class: PDD::Sources
- Inherits:
-
Object
- Object
- PDD::Sources
- Defined in:
- lib/pdd/sources.rb
Overview
Code base abstraction
Instance Method Summary collapse
- #exclude(ptn) ⇒ Object
-
#fetch ⇒ Object
Fetch all sources.
-
#initialize(dir, ptns = []) ⇒ Sources
constructor
Ctor.
Constructor Details
#initialize(dir, ptns = []) ⇒ Sources
Ctor.
dir-
Directory with source code files
30 31 32 33 |
# File 'lib/pdd/sources.rb', line 30 def initialize(dir, ptns = []) @dir = File.absolute_path(dir) @exclude = ptns + ['.git/**/*'] end |
Instance Method Details
#exclude(ptn) ⇒ Object
54 55 56 |
# File 'lib/pdd/sources.rb', line 54 def exclude(ptn) Sources.new(@dir, @exclude.push(ptn)) end |
#fetch ⇒ Object
Fetch all sources.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pdd/sources.rb', line 36 def fetch files = Dir.glob( File.join(@dir, '**/*'), File::FNM_DOTMATCH ).reject { |f| File.directory?(f) } excluded = 0 @exclude.each do |ptn| Dir.glob(File.join(@dir, ptn), File::FNM_DOTMATCH) do |f| files.delete_if { |i| i == f } excluded += 1 end end PDD.log.info "#{files.size} file(s) found, #{excluded} excluded" files.reject { |f| binary?(f) }.map do |file| path = file[@dir.length + 1, file.length] VerboseSource.new(path, Source.new(file, path)) end end |