class Rugsweep::Sweeper
Constants
- CONFIG_FILE
Public Class Methods
new(logger = STDOUT)
click to toggle source
# File lib/rugsweep/sweeper.rb, line 8 def initialize(logger = STDOUT) @logger = logger end
Public Instance Methods
log(str)
click to toggle source
# File lib/rugsweep/sweeper.rb, line 12 def log(str) @logger.puts str end
log_action(action, color, entry)
click to toggle source
# File lib/rugsweep/sweeper.rb, line 16 def log_action(action, color, entry) log format("(%s) %s", Paint[action, color], entry) end
log_existing(entry, _target)
click to toggle source
# File lib/rugsweep/sweeper.rb, line 20 def log_existing(entry, _target) log_action 'S', :yellow, entry end
log_move(entry, _target)
click to toggle source
# File lib/rugsweep/sweeper.rb, line 24 def log_move(entry, _target) log_action 'M', :green, entry end
sweep()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 28 def sweep ensure_dumping_ground_exists filtered_entries.each do |entry| target = dumping_ground.join(entry.basename) if target.exist? log_existing(entry, target) else log_move(entry, target) FileUtils.mv entry, dumping_ground end end end
Private Instance Methods
base()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 49 def base Pathname.new(".") end
config()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 64 def config @config ||= File.open(CONFIG_FILE) { |f| YAML.load(f) } end
dumping_ground()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 68 def dumping_ground @dumping_ground ||= base.join config.fetch("rug") end
ensure_dumping_ground_exists()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 43 def ensure_dumping_ground_exists dumping_ground.directory? || dumping_ground.mkdir end
entries()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 53 def entries base.children end
filtered_entries()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 57 def filtered_entries entries.reject do |entry| filter = Filter.new(entry, keep_files) filter.dotfile? || filter.ok? end end
keep_files()
click to toggle source
# File lib/rugsweep/sweeper.rb, line 72 def keep_files @keep_files ||= config.fetch("keep") + [dumping_ground.basename.to_s] end