Fix several rubocop issues with "rubocop -a"

This commit is contained in:
Nicolas McCurdy
2014-01-04 21:57:14 -05:00
parent f03e7670cf
commit fc2bbb1d6e
5 changed files with 50 additions and 82 deletions

View File

@@ -31,22 +31,22 @@ class Homesick < Thor
destination = nil
if File.exist?(uri)
uri = Pathname.new(uri).expand_path
raise "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
destination = uri.basename
ln_s uri, destination
elsif uri =~ GITHUB_NAME_REPO_PATTERN
destination = Pathname.new(uri).basename
git_clone "https://github.com/#{$1}.git", :destination => destination
git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/
destination = Pathname.new($1)
destination = Pathname.new(Regexp.last_match[1])
git_clone uri
elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/
destination = Pathname.new($1)
destination = Pathname.new(Regexp.last_match[1])
git_clone uri
else
raise "Unknown URI format: #{uri}"
fail "Unknown URI format: #{uri}"
end
if destination.join('.gitmodules').exist?
@@ -80,7 +80,7 @@ class Homesick < Thor
end
desc 'pull CASTLE', 'Update the specified castle'
method_option :all, :type => :boolean, :default => false, :required => false, :desc => 'Update all cloned castles'
method_option :all, type: :boolean, default: false, required: false, desc: 'Update all cloned castles'
def pull(name = DEFAULT_CASTLE_NAME)
if options[:all]
inside_each_castle do |castle|
@@ -90,13 +90,11 @@ class Homesick < Thor
else
update_castle name
end
end
desc 'commit CASTLE MESSAGE', "Commit the specified castle's changes"
def commit(name = DEFAULT_CASTLE_NAME, message = nil)
commit_castle name, message
end
desc 'push CASTLE', 'Push the specified castle'
@@ -122,7 +120,7 @@ class Homesick < Thor
end
desc 'symlink CASTLE', 'Symlinks all dotfiles from the specified castle'
method_option :force, :default => false, :desc => 'Overwrite existing conflicting symlinks without prompting.'
method_option :force, default: false, desc: 'Overwrite existing conflicting symlinks without prompting.'
def symlink(name = DEFAULT_CASTLE_NAME)
check_castle_existance(name, 'symlink')
@@ -231,20 +229,19 @@ class Homesick < Thor
end
end
desc "destroy CASTLE", "Delete all symlinks and remove the cloned repository"
desc 'destroy CASTLE', 'Delete all symlinks and remove the cloned repository'
def destroy(name)
check_castle_existance name, "destroy"
check_castle_existance name, 'destroy'
if shell.yes?("This will destroy your castle irreversible! Are you sure?")
if shell.yes?('This will destroy your castle irreversible! Are you sure?')
unlink(name)
rm_rf repos_dir.join(name)
end
end
desc "cd CASTLE", "Open a new shell in the root of the given castle"
desc 'cd CASTLE', 'Open a new shell in the root of the given castle'
def cd(castle = DEFAULT_CASTLE_NAME)
check_castle_existance castle, "cd"
check_castle_existance castle, 'cd'
castle_dir = repos_dir.join(castle)
say_status "cd #{castle_dir.realpath}", "Opening a new shell in castle '#{castle}'. To return to the original one exit from the new shell.", :green
inside castle_dir do
@@ -252,14 +249,14 @@ class Homesick < Thor
end
end
desc "open CASTLE", "Open your default editor in the root of the given castle"
desc 'open CASTLE', 'Open your default editor in the root of the given castle'
def open(castle = DEFAULT_CASTLE_NAME)
if !ENV['EDITOR']
say_status :error,"The $EDITOR environment variable must be set to use this command", :red
say_status :error, 'The $EDITOR environment variable must be set to use this command', :red
exit(1)
end
check_castle_existance castle, "open"
check_castle_existance castle, 'open'
castle_dir = repos_dir.join(castle)
say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", "Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.", :green
inside castle_dir do
@@ -297,7 +294,7 @@ class Homesick < Thor
def all_castles
dirs = Pathname.glob("#{repos_dir}/**/.git", File::FNM_DOTMATCH)
# reject paths that lie inside another castle, like git submodules
return dirs.reject do |dir|
dirs.reject do |dir|
dirs.any? do |other|
dir != other && dir.fnmatch(other.parent.join('*').to_s)
end
@@ -325,7 +322,7 @@ class Homesick < Thor
def commit_castle(castle, message)
check_castle_existance(castle, 'commit')
inside repos_dir.join(castle) do
git_commit_all :message => message
git_commit_all message: message
end
end

View File

@@ -78,12 +78,12 @@ class Homesick
def git_status(config = {})
say_status 'git status', '', :green unless options[:quiet]
system "git status" unless options[:pretend]
system 'git status' unless options[:pretend]
end
def git_diff(config = {})
say_status 'git diff', '', :green unless options[:quiet]
system "git diff" unless options[:pretend]
system 'git diff' unless options[:pretend]
end
def mv(source, destination, config = {})

View File

@@ -1,7 +1,6 @@
class Homesick
# Hack in support for diffing symlinks
class Shell < Thor::Shell::Color
def show_diff(destination, content)
destination = Pathname.new(destination)
@@ -12,6 +11,5 @@ class Homesick
super
end
end
end
end

View File

@@ -17,18 +17,12 @@ CyclomaticComplexity:
Documentation:
Enabled: false
EmptyLinesAroundBody:
Enabled: false
Eval:
Enabled: false
FavorUnlessOverNegatedIf:
Enabled: false
HashSyntax:
Enabled: false
IndentationWidth:
Enabled: false
@@ -38,26 +32,5 @@ LineLength:
MethodLength:
Max: 31
PerlBackrefs:
Enabled: false
RedundantReturn:
Enabled: false
RegexpLiteral:
Enabled: false
SignalException:
Enabled: false
SpaceAfterComma:
Enabled: false
SpaceAfterNot:
Enabled: false
SpaceAroundBlockBraces:
Enabled: false
StringLiterals:
Enabled: false

View File

@@ -99,7 +99,7 @@ describe 'homesick' do
end
it 'should clone a github repo' do
homesick.should_receive(:git_clone).with('https://github.com/wfarr/dotfiles.git', :destination => Pathname.new('dotfiles'))
homesick.should_receive(:git_clone).with('https://github.com/wfarr/dotfiles.git', destination: Pathname.new('dotfiles'))
homesick.clone 'wfarr/dotfiles'
end
@@ -165,7 +165,7 @@ describe 'homesick' do
end
context 'when forced' do
let(:homesick) { Homesick.new [], :force => true }
let(:homesick) { Homesick.new [], force: true }
it 'can override symlinks to directories' do
somewhere_else = create_construct
@@ -237,7 +237,7 @@ describe 'homesick' do
end
end
context "when call with no castle name" do
context 'when call with no castle name' do
let(:castle) { given_castle('dotfiles') }
it 'using default castle name: "dotfiles"' do
dotfile = castle.file('.some_dotfile')
@@ -320,7 +320,7 @@ describe 'homesick' do
end
end
context "when call with no castle name" do
context 'when call with no castle name' do
let(:castle) { given_castle('dotfiles') }
it 'using default castle name: "dotfiles"' do
@@ -484,7 +484,7 @@ describe 'homesick' do
some_nested_dir.realpath.should == tracked_file.realpath
end
context "when call with no castle name" do
context 'when call with no castle name' do
it 'using default castle name: "dotfiles"' do
castle = given_castle('dotfiles')
@@ -553,62 +553,62 @@ describe 'homesick' do
end
end
describe "destroy" do
it "removes the symlink files" do
describe 'destroy' do
it 'removes the symlink files' do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
given_castle("stronghold")
given_castle('stronghold')
some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold")
homesick.track(some_rc_file.to_s, 'stronghold')
homesick.destroy('stronghold')
some_rc_file.should_not be_exist
end
it "deletes the cloned repository" do
it 'deletes the cloned repository' do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
castle = given_castle("stronghold")
castle = given_castle('stronghold')
some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold")
homesick.track(some_rc_file.to_s, 'stronghold')
homesick.destroy('stronghold')
castle.should_not be_exist
end
end
describe "cd" do
describe 'cd' do
it "cd's to the root directory of the given castle" do
given_castle('castle_repo')
homesick.should_receive("inside").once.with(kind_of(Pathname)).and_yield
homesick.should_receive("system").once.with(ENV["SHELL"])
homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield
homesick.should_receive('system').once.with(ENV['SHELL'])
Capture.stdout { homesick.cd 'castle_repo' }
end
it "returns an error message when the given castle does not exist" do
homesick.should_receive("say_status").once.with(:error, /Could not cd castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red)
expect { homesick.cd "castle_repo" }.to raise_error(SystemExit)
it 'returns an error message when the given castle does not exist' do
homesick.should_receive('say_status').once.with(:error, /Could not cd castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red)
expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit)
end
end
describe "open" do
it "opens the system default editor in the root of the given castle" do
describe 'open' do
it 'opens the system default editor in the root of the given castle' do
ENV.stub(:[]).and_call_original # Make sure calls to ENV use default values for most things...
ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default value for 'EDITOR' just in case none is set
given_castle 'castle_repo'
homesick.should_receive("inside").once.with(kind_of(Pathname)).and_yield
homesick.should_receive("system").once.with('vim')
homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield
homesick.should_receive('system').once.with('vim')
Capture.stdout { homesick.open 'castle_repo' }
end
it "returns an error message when the $EDITOR environment variable is not set" do
it 'returns an error message when the $EDITOR environment variable is not set' do
ENV.stub(:[]).with('EDITOR').and_return(nil) # Set the default editor to make sure it fails.
homesick.should_receive("say_status").once.with(:error, "The $EDITOR environment variable must be set to use this command", :red)
expect { homesick.open "castle_repo" }.to raise_error(SystemExit)
homesick.should_receive('say_status').once.with(:error, 'The $EDITOR environment variable must be set to use this command', :red)
expect { homesick.open 'castle_repo' }.to raise_error(SystemExit)
end
it "returns an error message when the given castle does not exist" do
it 'returns an error message when the given castle does not exist' do
ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default just in case none is set
homesick.should_receive("say_status").once.with(:error, /Could not open castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red)
expect { homesick.open "castle_repo" }.to raise_error(SystemExit)
homesick.should_receive('say_status').once.with(:error, /Could not open castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red)
expect { homesick.open 'castle_repo' }.to raise_error(SystemExit)
end
end