lib/pdd/sources.rb in pdd-0.17.2 vs lib/pdd/sources.rb in pdd-0.17.3
- old
+ new
@@ -18,12 +18,14 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-require 'ptools'
+require 'pdd'
require 'pdd/source'
+require 'shellwords'
+require 'English'
module PDD
# Code base abstraction
class Sources
# Ctor.
@@ -33,25 +35,41 @@
@exclude = ptns + ['.git/**/*']
end
# Fetch all sources.
def fetch
- files = Dir.glob(File.join(@dir, '**/*'), File::FNM_DOTMATCH)
+ 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"
- files.select { |f| !File.directory?(f) && !File.binary?(f) }.map do |file|
+ 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
def exclude(ptn)
Sources.new(@dir, @exclude.push(ptn))
+ end
+
+ private
+
+ def binary?(f)
+ `grep -qI '.' #{Shellwords.escape(f)}`
+ if $CHILD_STATUS.success?
+ false
+ else
+ PDD.log.info "#{f} is a binary file (#{File.size(f)} bytes)"
+ true
+ end
end
end
end