From 9431cb78af0c5e42d3d33c0c792469ab9aa811fb Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Sat, 19 Jan 2019 18:45:56 -0500 Subject: [PATCH] Moved code to utils to reduce method complexity. --- lib/homesick/cli.rb | 13 +------------ lib/homesick/utils.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/homesick/cli.rb b/lib/homesick/cli.rb index b5ca84f..fbdfa88 100644 --- a/lib/homesick/cli.rb +++ b/lib/homesick/cli.rb @@ -24,18 +24,7 @@ module Homesick say_status :error, "Git version >= #{Homesick::Actions::GitActions::STRING} must be installed to use Homesick", :red exit(1) end - # Hack in support for diffing symlinks - # Also adds support for checking if destination or content is a directory - shell_metaclass = class << shell; self; end - shell_metaclass.send(:define_method, :show_diff) do |destination, source| - destination = Pathname.new(destination) - source = Pathname.new(source) - return 'Unable to create diff: destination or content is a directory' if destination.directory? || source.directory? - return super(destination, File.binread(source)) unless destination.symlink? - - say "- #{destination.readlink}", :red, true - say "+ #{source.expand_path}", :green, true - end + configure_symlinks_diff end desc 'clone URI CASTLE_NAME', 'Clone +uri+ as a castle with name CASTLE_NAME for homesick' diff --git a/lib/homesick/utils.rb b/lib/homesick/utils.rb index 6242d60..031b4ec 100644 --- a/lib/homesick/utils.rb +++ b/lib/homesick/utils.rb @@ -212,5 +212,20 @@ module Homesick end false end + + def configure_symlinks_diff + # Hack in support for diffing symlinks + # Also adds support for checking if destination or content is a directory + shell_metaclass = class << shell; self; end + shell_metaclass.send(:define_method, :show_diff) do |destination, source| + destination = Pathname.new(destination) + source = Pathname.new(source) + return 'Unable to create diff: destination or content is a directory' if destination.directory? || source.directory? + return super(destination, File.binread(source)) unless destination.symlink? + + say "- #{destination.readlink}", :red, true + say "+ #{source.expand_path}", :green, true + end + end end end