From 2830ee82d84380633002fcbde496bb56e3ddbe3a Mon Sep 17 00:00:00 2001
From: Victor Goff <keeperotphones@gmail.com>
Date: Tue, 8 Sep 2015 17:41:10 -0400
Subject: [PATCH] Use the existing Rubocop configuration

Unsure why so many style issues/inconsistencies when it is obvious there
are style opinions, as provided by the .rubocop.yml file.
---
 Gemfile                              |  2 +-
 Rakefile                             |  9 ++---
 lib/mob_rotation/command_routing.rb  |  8 ++--
 lib/mob_rotation/rotation.rb         | 59 +++++++++++++---------------
 spec/database_spec.rb                | 14 +++----
 spec/foo_fighter_spec.rb             |  4 +-
 spec/mob_rotation_executable_spec.rb | 22 +++++------
 spec/rotation_spec.rb                |  4 +-
 8 files changed, 58 insertions(+), 64 deletions(-)

diff --git a/Gemfile b/Gemfile
index 3772ef8..90b2f5f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,4 @@
-source 'https://rubygems.org'
+source "https://rubygems.org"
 
 # Specify your gem's dependencies in mob_rotation.gemspec
 gemspec
diff --git a/Rakefile b/Rakefile
index 7a3ecd1..f00c6df 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,9 +1,8 @@
 require "bundler/gem_tasks"
-require 'rake/testtask'
-require 'rspec/core/rake_task'
+require "rake/testtask"
+require "rspec/core/rake_task"
 
 RSpec::Core::RakeTask.new(:test)
 desc "Default task is test or spec"
-task :spec => :test
-task :default => :test
-
+task spec: :test
+task default: :test
diff --git a/lib/mob_rotation/command_routing.rb b/lib/mob_rotation/command_routing.rb
index 767a550..a8736f4 100644
--- a/lib/mob_rotation/command_routing.rb
+++ b/lib/mob_rotation/command_routing.rb
@@ -9,11 +9,11 @@ def define_command(name, &block)
     end
 
     def command_router(command, mobster_names)
-      command_implementation = CommandRouting::COMMAND_MAPPINGS.fetch(command) {
-        lambda { |command|
+      command_implementation = CommandRouting::COMMAND_MAPPINGS.fetch(command) do
+        lambda do |command|
           inform_lovely_user(command)
-        }
-      }
+        end
+      end
       case command_implementation.arity
       when -2
         instance_exec(command, *mobster_names, &command_implementation)
diff --git a/lib/mob_rotation/rotation.rb b/lib/mob_rotation/rotation.rb
index dbcbfa4..dc3bb2d 100644
--- a/lib/mob_rotation/rotation.rb
+++ b/lib/mob_rotation/rotation.rb
@@ -44,7 +44,7 @@ def initialize(database, git_dir)
       @git_dir = git_dir
       @database = database
 
-      @real_mobsters = @database.sanitized_entries_in do | entry |
+      @real_mobsters = @database.sanitized_entries_in do |entry|
         mobster = build_mobster entry
       end
     end
@@ -70,17 +70,17 @@ def show_mobsters
       end
     end
 
-    def format_mobster(role, person, color=nil)
-      width = ENV['TABLE'] ? "navigator".size : 0
+    def format_mobster(role, person, color = nil)
+      width = ENV["TABLE"] ? "navigator".size : 0
       role = sprintf("%-#{width}s", role)
 
       formatted = if person.email.to_s.empty?
-        "#{role} #{person.name}"
-      else
-        "#{role} #{person.name} <#{person.email}>"
+                    "#{role} #{person.name}"
+                  else
+                    "#{role} #{person.name} <#{person.email}>"
       end
 
-      if color && ENV['COLOR']
+      if color && ENV["COLOR"]
         formatted.send color
       else
         formatted
@@ -89,7 +89,7 @@ def format_mobster(role, person, color=nil)
 
     def add_mobster(*mobsters_to_add)
       mobsters_to_add.map(&:to_s).map(&:strip).each do |mobster_to_add|
-        raise if mobster_to_add.empty?
+        fail if mobster_to_add.empty?
 
         if @real_mobsters.map(&:name).include?(mobster_to_add)
           puts "user name '#{mobster_to_add}' already exists"
@@ -104,9 +104,7 @@ def add_mobster(*mobsters_to_add)
 
     def remove_mobster(given_mobster)
       @real_mobsters.each_with_index do |mobster, i|
-        if found_mobster(mobster, given_mobster)
-          @real_mobsters.delete_at(i)
-        end
+        @real_mobsters.delete_at(i) if found_mobster(mobster, given_mobster)
       end
       sync
     end
@@ -118,22 +116,22 @@ def remove_mobsters(*mobsters)
     end
 
     def show_help
-      puts ['Available commands are:',
-      'show',
-      'help',
-      'rotate',
-      'random',
-      'add <name1> [name2]',
-      'remove <name1> [name2]',
-      'run_with_timer [seconds]'
-      ]
-    end
-
-    def self.annoying_and_probably_not_accidental_beep(n=number_of_beeps)
+      puts ["Available commands are:",
+            "show",
+            "help",
+            "rotate",
+            "random",
+            "add <name1> [name2]",
+            "remove <name1> [name2]",
+            "run_with_timer [seconds]"
+           ]
+    end
+
+    def self.annoying_and_probably_not_accidental_beep(n = number_of_beeps)
       n.times { print("\a") || sleep(minimum_sleep_between_beeps) }
     end
 
-    def countdown_to_rotate(seconds=300)
+    def countdown_to_rotate(seconds = 300)
       sleep(seconds)
       puts "Time to rotate"
       self.class.annoying_and_probably_not_accidental_beep
@@ -159,7 +157,7 @@ def rotate
       end
     end
 
-    def random(seed=nil)
+    def random(seed = nil)
       puts "Randomized Output"
 
       rotate_mobsters do
@@ -173,7 +171,6 @@ def extract_next_mobster_email
       email.empty? ? "mob@rubysteps.com" : email
     end
 
-
     def time_to_rotate
       puts "Time to rotate!"
     end
@@ -187,20 +184,18 @@ def self.number_of_beeps
     end
 
     def extract_name_from(entry)
-      entry_to_array = entry.split('')
-      entry_to_array.take_while { |c| c != '<' }.join('').strip
+      entry_to_array = entry.split("")
+      entry_to_array.take_while { |c| c != "<" }.join("").strip
     end
 
     def extract_email_from(entry)
-      result = if entry =~ /\<(.*)\>/
-        $1
-      end
+      result = Regexp.last_match(1) if entry =~ /\<(.*)\>/
     end
 
     private
 
     def git_config_update
-      #FIX yo that rescue nil is bogus
+      # FIX yo that rescue nil is bogus
       system "git --git-dir=#{@git_dir} config user.name '#{@real_mobsters.first.name}'" rescue nil
       system "git --git-dir=#{@git_dir} config user.email '#{extract_next_mobster_email}'" rescue nil
     end
diff --git a/spec/database_spec.rb b/spec/database_spec.rb
index fab81fb..e717960 100644
--- a/spec/database_spec.rb
+++ b/spec/database_spec.rb
@@ -1,15 +1,15 @@
-require_relative 'spec_helper'
+require_relative "spec_helper"
 
 describe MobRotation::Database do
-  let(:temp_rotation_db) { '/tmp/rotation_test.txt' }
+  let(:temp_rotation_db) { "/tmp/rotation_test.txt" }
 
-  it 'formats the mobster, maintaining original name and email data' do
+  it "formats the mobster, maintaining original name and email data" do
     database = MobRotation::Database.new(temp_rotation_db)
 
-    name, email = "   David    ", " david.is.great@i.am.fab.com      "
-    formatted_name_and_email = database.format_mobster(name,email)
+    name = "   David    "
+    email = " david.is.great@i.am.fab.com      "
+    formatted_name_and_email = database.format_mobster(name, email)
 
-    expect(formatted_name_and_email).to eq('   David     < david.is.great@i.am.fab.com      >')
+    expect(formatted_name_and_email).to eq("   David     < david.is.great@i.am.fab.com      >")
   end
-
 end
diff --git a/spec/foo_fighter_spec.rb b/spec/foo_fighter_spec.rb
index a586257..5107370 100644
--- a/spec/foo_fighter_spec.rb
+++ b/spec/foo_fighter_spec.rb
@@ -2,7 +2,7 @@
 
 describe FooFighter do
   it "raises an error when a class defines `#foo`" do
-    expect {
+    expect do
       class TestClass
         extend FooFighter
 
@@ -10,7 +10,7 @@ def foo
           "shouldn't work"
         end
       end
-    }.to raise_error(/no foo for you/)
+    end.to raise_error(/no foo for you/)
   end
 
   it "removes a method named `#foo`" do
diff --git a/spec/mob_rotation_executable_spec.rb b/spec/mob_rotation_executable_spec.rb
index 039cc81..ac21b25 100644
--- a/spec/mob_rotation_executable_spec.rb
+++ b/spec/mob_rotation_executable_spec.rb
@@ -40,7 +40,7 @@ def run_rotate_with_specified_redirect(command = nil, env = nil, redirect = nil)
 
   def our_output
     @our_output ||= File.readlines("./tmp/results.txt").collect(&:strip)
-      .reject(&:empty?)
+                    .reject(&:empty?)
   end
 
   context "command: ruby mob_rotation" do
@@ -133,7 +133,7 @@ def our_output
       run_rotate("random 0")
 
       git_username = `git --git-dir=./tmp/test_project/.git config user.name`
-        .strip
+                     .strip
       expect(git_username).to eq("Phoebe Example")
     end
   end
@@ -208,7 +208,7 @@ def our_output
         run_rotate("rotate")
 
         git_username = `git --git-dir=./tmp/test_project/.git config user.name`
-          .strip
+                       .strip
         expect(git_username).to eq("Phoebe Example")
       end
 
@@ -219,7 +219,7 @@ def our_output
         run_rotate("rotate")
 
         git_email = `git --git-dir=./tmp/test_project/.git config user.email`
-          .strip
+                    .strip
         expect(git_email).to eq("phoebe@example.com")
       end
 
@@ -233,7 +233,7 @@ def our_output
         run_rotate("rotate")
 
         git_email = `git --git-dir=./tmp/test_project/.git config user.email`
-          .strip
+                    .strip
         expect(git_email).to eq("joe@example.com")
       end
 
@@ -245,9 +245,9 @@ def our_output
         run_rotate("rotate")
 
         git_email = `git --git-dir=./tmp/test_project/.git config user.email`
-          .strip
+                    .strip
         git_global_user_email = `git config --global user.email`
-          .strip  
+                                .strip
         expect(git_email).to eq(git_global_user_email)
       end
 
@@ -261,7 +261,7 @@ def our_output
         run_rotate("rotate")
 
         git_email = `git --git-dir=./tmp/test_project/.git config user.email`
-          .strip
+                    .strip
         expect(git_email).to eq("joe@example.com")
       end
     end
@@ -287,7 +287,7 @@ def our_output
       run_rotate("add Ralph")
 
       expect(our_output).to include("user name 'Ralph' already exists")
-      expect(our_output.select { |l| l.include?("Ralph") }.size).to eq(2)
+      expect(our_output.count { |l| l.include?("Ralph") }).to eq(2)
     end
   end
 
@@ -317,9 +317,9 @@ def our_output
     end
 
     it "waits until time runs out before stating 'Time to Rotate'" do
-      expect {
+      expect do
         Timeout.timeout(1) { run_rotate("run_with_timer 5") }
-      }.to raise_error(Timeout::Error)
+      end.to raise_error(Timeout::Error)
       expect(our_output).to eq([])
     end
 
diff --git a/spec/rotation_spec.rb b/spec/rotation_spec.rb
index 86c97d8..85fe867 100644
--- a/spec/rotation_spec.rb
+++ b/spec/rotation_spec.rb
@@ -3,12 +3,12 @@
 describe MobRotation::Rotation do
   extend FooFighter
 
-  let(:mob_rotator) {
+  let(:mob_rotator) do
     MobRotation::Rotation.new(
       MobRotation::Database.new(file_name),
       "./tmp/test_project/.git"
     )
-  }
+  end
 
   before { FileUtils.rm_f(file_name) }