Refactor the ln_s method to decrease its cyclomatic complexity
This commit is contained in:
@@ -10,7 +10,7 @@ ClassLength:
|
|||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
CyclomaticComplexity:
|
CyclomaticComplexity:
|
||||||
Max: 9
|
Max: 7
|
||||||
|
|
||||||
LineLength:
|
LineLength:
|
||||||
Max: 163
|
Max: 163
|
||||||
|
|||||||
@@ -387,6 +387,10 @@ class Homesick < Thor
|
|||||||
first_p.mtime > second_p.mtime && !first_p.symlink?
|
first_p.mtime > second_p.mtime && !first_p.symlink?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collision_accepted?
|
||||||
|
options[:force] || shell.file_collision(destination) { source }
|
||||||
|
end
|
||||||
|
|
||||||
def each_file(castle, basedir, subdirs)
|
def each_file(castle, basedir, subdirs)
|
||||||
absolute_basedir = Pathname.new(basedir).expand_path
|
absolute_basedir = Pathname.new(basedir).expand_path
|
||||||
inside basedir do
|
inside basedir do
|
||||||
|
|||||||
@@ -148,18 +148,16 @@ class Homesick
|
|||||||
destination = Pathname.new(destination)
|
destination = Pathname.new(destination)
|
||||||
FileUtils.mkdir_p destination.dirname
|
FileUtils.mkdir_p destination.dirname
|
||||||
|
|
||||||
if destination.symlink?
|
if destination.symlink? && destination.readlink == source
|
||||||
if destination.readlink == source
|
|
||||||
say_status :identical, destination.expand_path, :blue unless options[:quiet]
|
say_status :identical, destination.expand_path, :blue unless options[:quiet]
|
||||||
else
|
elsif destination.symlink?
|
||||||
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]
|
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]
|
||||||
|
|
||||||
system "ln -nsf '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend]
|
smart_system "ln -nsf '#{source}' '#{destination}'" if collision_accepted?
|
||||||
end
|
|
||||||
elsif destination.exist?
|
elsif destination.exist?
|
||||||
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
|
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
|
||||||
|
|
||||||
if options[:force] || shell.file_collision(destination) { source }
|
if collision_accepted?
|
||||||
system "rm -rf '#{destination}'" unless options[:pretend]
|
system "rm -rf '#{destination}'" unless options[:pretend]
|
||||||
system "ln -sf '#{source}' '#{destination}'" unless options[:pretend]
|
system "ln -sf '#{source}' '#{destination}'" unless options[:pretend]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user