class FileNameHistory

Attributes

current[R]
history[R]

Public Class Methods

new(name, history = []) click to toggle source
# File lib/filename_history.rb, line 7
def initialize(name, history = [])
  @history = history.empty? ? [name] : history
  @current = name
end
new_from_history(history) click to toggle source
# File lib/filename_history.rb, line 18
def self.new_from_history(history)
  FileNameHistory.new(history.last,
                      history)
end

Public Instance Methods

changed?() click to toggle source
# File lib/filename_history.rb, line 56
def changed?
  @history.last != @current
end
current_color() click to toggle source
# File lib/filename_history.rb, line 74
def current_color
  @current_color || @current
end
last_color() click to toggle source
# File lib/filename_history.rb, line 70
def last_color
  @last_color || last_name
end
last_name() click to toggle source
# File lib/filename_history.rb, line 31
def last_name
  @history.last
end
log(where = $stdout) click to toggle source
# File lib/filename_history.rb, line 78
def log(where = $stdout)
  return unless changed?
  where.puts(current_color)
  where.puts("-> #{last_color}")
end
original() click to toggle source
# File lib/filename_history.rb, line 27
def original
  @history.first
end
plan_reapplication(name) click to toggle source
# File lib/filename_history.rb, line 52
def plan_reapplication(name)
  @current = name
end
plan_rename(regexp, replacement) click to toggle source
# File lib/filename_history.rb, line 35
def plan_rename(regexp, replacement)
  new_name = @current.gsub(regexp, replacement)
  if new_name != current
    @current_color = @current.gsub(regexp, '\0'.colorize(:color => :green))
    @last_color = @current.gsub(regexp, replacement.colorize(:color => :cyan))
    @history << new_name
  end
end
plan_rollback() click to toggle source
# File lib/filename_history.rb, line 44
def plan_rollback
  @history << original
end
present?() click to toggle source
# File lib/filename_history.rb, line 23
def present?
  File.exist?(@current)
end
print_history(where = $stdout) click to toggle source
rename() click to toggle source
# File lib/filename_history.rb, line 60
def rename
  File.rename("#{@current}", "#{@history.last}")
  @current = @history.last
end
to_hash() click to toggle source
# File lib/filename_history.rb, line 12
def to_hash
  {
    @history.last => @history
  }
end
was_named?(name) click to toggle source
# File lib/filename_history.rb, line 48
def was_named?(name)
  @history.include? name
end