Class: PDD::Sources

Inherits:
Object
  • Object
show all
Defined in:
lib/pdd/sources.rb

Overview

Code base abstraction

Instance Method Summary collapse

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

#fetchObject

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