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
33 34 35 36 |
# File 'lib/pdd/sources.rb', line 33 def initialize(dir, ptns = []) @dir = dir @exclude = ptns + ['.git/**/*'] end |
Instance Method Details
#exclude(ptn) ⇒ Object
59 60 61 |
# File 'lib/pdd/sources.rb', line 59 def exclude(ptn) Sources.new(@dir, @exclude.push(ptn)) end |
#fetch ⇒ Object
Fetch all sources.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pdd/sources.rb', line 39 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| VerboseSource.new( file, Source.new(file, file[@dir.length + 1, file.length]) ) end end |