module CleanupVendor
Constants
- CONFIG_FILE
- DEFAULTS
- VERSION
Public Class Methods
filter(dir, opts = {}) { |path| ... }
click to toggle source
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# File lib/cleanup_vendor.rb, line 32 def filter(dir, opts = {}) raise Error, 'Not a directory' unless File.directory?(dir.to_s) return to_enum(:filter, dir, opts) unless block_given? files, directories, filtered, exclude = get_options(opts) Path.new(dir).recursive_entries do |path| next if path.match?(exclude) next if path.include?(filtered) next unless path.file? && path.match?(files) || path.directory? && path.match?(directories) filtered << path yield(path) end end
run(dir, opts = {})
click to toggle source
# File lib/cleanup_vendor.rb, line 16 def run(dir, opts = {}) summary = [] filter(dir, DEFAULTS.merge(opts)) do |p| summary << p.summary if opts[:summary] print_verbose(p) if opts[:verbose] print_path(p) if opts[:print0] FileUtils.remove_entry(p) unless opts[:dry_run] end print_summary(summary) if opts[:summary] end
Private Class Methods
format_summary(prefix, number)
click to toggle source
# File lib/cleanup_vendor.rb, line 56 def format_summary(prefix, number) "\t#{prefix}\t#{number.to_s.rjust(20)}" end
get_options(options)
click to toggle source
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# File lib/cleanup_vendor.rb, line 49 def get_options(options) options.values_at(:files, :directories, :filtered, :exclude).map do |v| (v || []).to_set end end
print_path(path)
click to toggle source
# File lib/cleanup_vendor.rb, line 66 def print_path(path) $stdout.write path $stdout.putc 0 end
print_summary(summary)
click to toggle source
# File lib/cleanup_vendor.rb, line 72 def print_summary(summary) all_files = summary.flatten count = all_files.count blocks = all_files.map(&:blocks).sum bytes = all_files.map(&:size).sum $stderr.puts 'Summary:' $stderr.puts format_summary('Removed files:', count) $stderr.puts format_summary('Total blocks:', blocks) $stderr.puts format_summary('Total bytes:', bytes) end
print_verbose(path)
click to toggle source
# File lib/cleanup_vendor.rb, line 61 def print_verbose(path) $stderr.puts "Removing #{path}..." end