2014-10-26 18:32:46 +01:00
|
|
|
# Formatter for diff output
|
|
|
|
module Differ
|
|
|
|
module Format
|
|
|
|
# Try to format as unified diff, using - and +
|
|
|
|
module Patch
|
|
|
|
class << self
|
|
|
|
def format(change)
|
|
|
|
case
|
|
|
|
when change.change?
|
|
|
|
as_change change
|
|
|
|
when change.delete?
|
|
|
|
as_delete change
|
|
|
|
when change.insert?
|
|
|
|
as_insert change
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def as_insert(change)
|
|
|
|
"+ #{change.insert}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_delete(change)
|
|
|
|
"- #{change.delete}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_change(change)
|
2014-10-27 11:17:17 +01:00
|
|
|
[as_delete(change), as_insert(change)].join "\n"
|
2014-10-26 18:32:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|