Separate the action handling of ln_s into a new method to lower complexity

This commit is contained in:
Nicolas McCurdy
2014-01-09 01:00:40 -05:00
parent 0bbb82f9ba
commit bb735763c6
2 changed files with 19 additions and 8 deletions

View File

@@ -9,8 +9,5 @@ Eval:
ClassLength:
Enabled: false
CyclomaticComplexity:
Max: 7
MethodLength:
Max: 36

View File

@@ -156,17 +156,31 @@ class Homesick
destination = Pathname.new(destination)
FileUtils.mkdir_p destination.dirname
if destination.symlink? && destination.readlink == source
say_status :identical, destination.expand_path, :blue unless options[:quiet]
action = if destination.symlink? && destination.readlink == source
:identical
elsif destination.symlink?
:symlink_conflict
elsif destination.exist?
:conflict
else
:success
end
handle_symlink_action action, source, destination
end
def handle_symlink_action(action, source, destination)
case action
when :identical
say_status :identical, destination.expand_path, :blue unless options[:quiet]
when :symlink_conflict
say_status :conflict,
"#{destination} exists and points to " \
"#{destination.readlink}",
:red unless options[:quiet]
smart_system "ln -nsf '#{source}' '#{destination}'" \
if collision_accepted?
elsif destination.exist?
system "ln -nsf '#{source}' '#{destination}'" if collision_accepted?
when :conflict
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
if collision_accepted?