lib/pdd/sources.rb in pdd-0.2.3 vs lib/pdd/sources.rb in pdd-0.3
- old
+ new
@@ -21,27 +21,40 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
require 'filemagic'
require 'pdd/source'
+require 'rake/file_list'
module PDD
# Code base abstraction
class Sources
# Ctor.
# +dir+:: Directory with source code files
- def initialize(dir)
+ def initialize(dir, ptns = [])
@dir = dir
+ @exclude = ptns
@magic = FileMagic.new(FileMagic::MAGIC_MIME)
end
# Fetch all sources.
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/]
- Dir.glob(@dir + '/**/*')
+ 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
+
+ def exclude(ptn)
+ Sources.new(@dir, @exclude.push(ptn))
end
end
end