From 7bafee35a7e4edd2be7d22dbcf80f22ab217a20c Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 3 Feb 2019 11:14:23 +1100 Subject: [PATCH] (rubocop) Fix Style/IfUnlessModifier --- lib/vmfloaty.rb | 8 ++------ lib/vmfloaty/auth.rb | 8 ++------ lib/vmfloaty/http.rb | 24 ++++++------------------ lib/vmfloaty/nonstandard_pooler.rb | 4 +--- lib/vmfloaty/pooler.rb | 8 ++------ lib/vmfloaty/ssh.rb | 4 +--- lib/vmfloaty/utils.rb | 4 +--- 7 files changed, 15 insertions(+), 45 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 2d587e2..17947d9 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -212,9 +212,7 @@ class Vmfloaty # Confirm deletion puts confirmed = true - unless force - confirmed = agree('Delete all these VMs? [y/N]') - end + confirmed = agree('Delete all these VMs? [y/N]') unless force if confirmed response = service.delete(verbose, running_vms) response.each do |hostname, result| @@ -381,9 +379,7 @@ class Vmfloaty puts result when 'status' token_value = options.token - if token_value.nil? - token_value = args[1] - end + token_value = args[1] if token_value.nil? status = service.token_status(verbose, token_value) puts status when nil diff --git a/lib/vmfloaty/auth.rb b/lib/vmfloaty/auth.rb index bbe7425..091b7c2 100644 --- a/lib/vmfloaty/auth.rb +++ b/lib/vmfloaty/auth.rb @@ -20,9 +20,7 @@ class Auth end def self.delete_token(verbose, url, user, password, token) - if token.nil? - raise TokenError, 'You did not provide a token' - end + raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn_with_auth(verbose, url, user, password) @@ -36,9 +34,7 @@ class Auth end def self.token_status(verbose, url, token) - if token.nil? - raise TokenError, 'You did not provide a token' - end + raise TokenError, 'You did not provide a token' if token.nil? conn = Http.get_conn(verbose, url) diff --git a/lib/vmfloaty/http.rb b/lib/vmfloaty/http.rb index bb7636e..860df2b 100644 --- a/lib/vmfloaty/http.rb +++ b/lib/vmfloaty/http.rb @@ -11,21 +11,15 @@ class Http uri = URI.parse(url) - if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) - return true - end + return true if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) false end def self.get_conn(verbose, url) - if url.nil? - raise 'Did not provide a url to connect to' - end + raise 'Did not provide a url to connect to' if url.nil? - unless is_url(url) - url = "https://#{url}" - end + url = "https://#{url}" unless is_url(url) conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded @@ -37,17 +31,11 @@ class Http end def self.get_conn_with_auth(verbose, url, user, password) - if url.nil? - raise 'Did not provide a url to connect to' - end + raise 'Did not provide a url to connect to' if url.nil? - if user.nil? - raise 'You did not provide a user to authenticate with' - end + raise 'You did not provide a user to authenticate with' if user.nil? - unless is_url(url) - url = "https://#{url}" - end + url = "https://#{url}" unless is_url(url) conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| faraday.request :url_encoded diff --git a/lib/vmfloaty/nonstandard_pooler.rb b/lib/vmfloaty/nonstandard_pooler.rb index 512e90d..aacb6bb 100644 --- a/lib/vmfloaty/nonstandard_pooler.rb +++ b/lib/vmfloaty/nonstandard_pooler.rb @@ -94,9 +94,7 @@ class NonstandardPooler response_body = {} - unless hosts.is_a? Array - hosts = hosts.split(',') - end + hosts = hosts.split(',') unless hosts.is_a? Array hosts.each do |host| response = conn.delete "host/#{host}" res_body = JSON.parse(response.body) diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index a84035b..2c0b934 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -35,9 +35,7 @@ class Pooler # Developers can use `Utils.generate_os_hash` to # generate the os_type param. conn = Http.get_conn(verbose, url) - if token - conn.headers['X-AUTH-TOKEN'] = token - end + conn.headers['X-AUTH-TOKEN'] = token if token os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') if os_string.empty? @@ -106,9 +104,7 @@ class Pooler conn = Http.get_conn(verbose, url) - if token - conn.headers['X-AUTH-TOKEN'] = token - end + conn.headers['X-AUTH-TOKEN'] = token if token response_body = {} diff --git a/lib/vmfloaty/ssh.rb b/lib/vmfloaty/ssh.rb index c5c63c6..848d054 100644 --- a/lib/vmfloaty/ssh.rb +++ b/lib/vmfloaty/ssh.rb @@ -17,9 +17,7 @@ class Ssh def self.ssh(verbose, host_os, token, url) ssh_path = which('ssh') - if !ssh_path - raise 'Could not determine path to ssh' - end + raise 'Could not determine path to ssh' if !ssh_path os_types = {} os_types[host_os] = 1 diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index 763bb8f..b42bfaa 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -41,9 +41,7 @@ class Utils response_body.each do |os, value| hostnames = Array(value['hostname']) - if domain - hostnames.map! {|host| "#{host}.#{domain}"} - end + hostnames.map! {|host| "#{host}.#{domain}"} if domain result[os] = hostnames end