class RenameGem::Renamer::DirectoryHandler
Attributes
context[R]
path[R]
results[R]
Public Class Methods
new(context)
click to toggle source
# File lib/rename_gem/renamer/directory_handler.rb, line 8 def initialize(context) @context = context @path = Path.new(context.path, context.pwd) @results = [] end
Public Instance Methods
change_files()
click to toggle source
# File lib/rename_gem/renamer/directory_handler.rb, line 14 def change_files path.files.each do |pathname| file_handler = FileHandler.new(pathname) results << "Edit #{pathname.path}" if file_handler.edit(context.from, context.to) results << "Rename #{pathname.path} -> #{file_handler.path.filename}" if file_handler.rename(context.from, context.to) end end
directories()
click to toggle source
# File lib/rename_gem/renamer/directory_handler.rb, line 36 def directories path.directories.map do |directory_path| self.class.new(context.using(directory_path.path)) end end
rename()
click to toggle source
# File lib/rename_gem/renamer/directory_handler.rb, line 23 def rename built_path = path.build(replacement(path.filename)) FileUtils.mv(path.to_s, built_path.to_s) results << "Rename #{path.path} -> #{built_path.filename}" @path = built_path true rescue StringReplacer::NoMatchError false end
Private Instance Methods
replacement(text)
click to toggle source
# File lib/rename_gem/renamer/directory_handler.rb, line 44 def replacement(text) replacer = StringReplacer.new(text) replacer.replace(context.from).with(context.to) end