lib/pdd/sources.rb in pdd-0.20.6 vs lib/pdd/sources.rb in pdd-0.20.7
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2014-2020 Yegor Bugayenko
+# Copyright (c) 2014-2021 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -28,17 +28,26 @@
# Ctor.
# +dir+:: Directory with source code files
def initialize(dir, ptns = [])
@dir = File.absolute_path(dir)
@exclude = ptns + ['.git/**/*']
+ @include = ptns + ['.git/**/*']
end
# Fetch all sources.
def fetch
files = Dir.glob(
File.join(@dir, '**/*'), File::FNM_DOTMATCH
).reject { |f| File.directory?(f) }
+ included = 0
+ @include.each do |ptn|
+ Dir.glob(File.join(@dir, ptn), File::FNM_DOTMATCH) do |f|
+ files.keep_if { |i| i != f }
+ included += 1
+ end
+ end
+ PDD.log.info "#{files.size} file(s) found, #{included} files included"
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
@@ -51,9 +60,13 @@
end
end
def exclude(ptn)
Sources.new(@dir, @exclude.push(ptn))
+ end
+
+ def include(ptn)
+ Sources.new(@dir, @include.push(ptn))
end
private
# @todo #98:30min Change the implementation of this method