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 37 |
# File 'lib/pdd/sources.rb', line 33 def initialize(dir, ptns = []) @dir = dir @exclude = ptns @magic = FileMagic.new(FileMagic::MAGIC_MIME) end |
Instance Method Details
#exclude(ptn) ⇒ Object
56 57 58 |
# File 'lib/pdd/sources.rb', line 56 def exclude(ptn) Sources.new(@dir, @exclude.push(ptn)) end |
#fetch ⇒ Object
Fetch all sources.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pdd/sources.rb', line 40 def fetch files = Rake::FileList.new(@dir + '/**/*') do |list| @exclude.each do |ptn| Rake::FileList.new(@dir + '/' + ptn).each do |f| list.exclude(f) end end end types = [/^text\//, /application\/xml/] files.to_a .select { |f| types.index { |re| @magic.file(f) =~ re } } .map do |file| Source.new(file, file[@dir.length + 1, file.length]) end end |