From bbaebe06028fefb573ecd2d81e4329aef48182a7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 11 Jan 2018 19:08:04 +0100 Subject: [PATCH] !foo.nil? -> foo.present? --- app/controllers/api_controller.rb | 2 +- app/controllers/users/dossiers/invites_controller.rb | 2 +- app/models/cerfa.rb | 2 +- app/models/champ.rb | 4 ++-- app/models/drop_down_list.rb | 2 +- app/models/piece_justificative.rb | 2 +- app/models/user.rb | 2 +- app/services/switch_devise_profile_service.rb | 6 +++--- app/views/dossiers/_infos_dossier.html.haml | 2 +- app/views/dossiers/_infos_pieces_jointes.html.haml | 2 +- app/views/dossiers/_pieces_justificatives.html.haml | 2 +- lib/tasks/cloud_storage.rake | 4 ++-- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index ebbdb7049..255f9809a 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -9,7 +9,7 @@ class APIController < ApplicationController protected def valid_token? - !current_administrateur.nil? + current_administrateur.present? end def current_administrateur diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb index c890dc6c8..bb891eddd 100644 --- a/app/controllers/users/dossiers/invites_controller.rb +++ b/app/controllers/users/dossiers/invites_controller.rb @@ -1,7 +1,7 @@ class Users::Dossiers::InvitesController < UsersController def authenticate_user! session["user_return_to"] = request.fullpath - return redirect_to new_user_registration_path(user_email: params[:email]) if !params[:email].blank? && User.find_by_email(params[:email]).nil? + return redirect_to new_user_registration_path(user_email: params[:email]) if params[:email].present? && User.find_by_email(params[:email]).nil? super end diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index c64831445..d1da7b9d3 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -5,7 +5,7 @@ class Cerfa < ActiveRecord::Base mount_uploader :content, CerfaUploader validates :content, :file_size => {:maximum => 20.megabytes} - after_save :internal_notification, if: Proc.new { !dossier.nil? } + after_save :internal_notification, if: Proc.new { dossier.present? } def empty? content.blank? diff --git a/app/models/champ.rb b/app/models/champ.rb index 5eb554853..d5932bef6 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -9,7 +9,7 @@ class Champ < ActiveRecord::Base before_save :serialize_datetime_if_needed, if: Proc.new { type_champ == 'datetime' } before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' } - after_save :internal_notification, if: Proc.new { !dossier.nil? } + after_save :internal_notification, if: Proc.new { dossier.present? } scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } @@ -39,7 +39,7 @@ class Champ < ActiveRecord::Base end def same_date? num, compare - if type_champ == 'datetime' && !value.nil? + if type_champ == 'datetime' && value.present? if value.to_datetime.strftime(compare) == num return true end diff --git a/app/models/drop_down_list.rb b/app/models/drop_down_list.rb index 150bebb73..91e49f9b3 100644 --- a/app/models/drop_down_list.rb +++ b/app/models/drop_down_list.rb @@ -7,7 +7,7 @@ class DropDownList < ActiveRecord::Base end def disabled_options - options.select{ |v| !(v =~ /^--.*--$/).nil? } + options.select{ |v| (v =~ /^--.*--$/).present? } end def selected_options(champ) diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 384d6a5f8..468fb0fa7 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -13,7 +13,7 @@ class PieceJustificative < ActiveRecord::Base validates :content, :file_size => {:maximum => 20.megabytes} validates :content, presence: true, allow_blank: false, allow_nil: false - after_save :internal_notification, if: Proc.new { !dossier.nil? } + after_save :internal_notification, if: Proc.new { dossier.present? } scope :updated_since?, -> (date) { where('pieces_justificatives.updated_at > ?', date) } diff --git a/app/models/user.rb b/app/models/user.rb index 3189c652d..16d5edca6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,7 +31,7 @@ class User < ActiveRecord::Base end def loged_in_with_france_connect? - !loged_in_with_france_connect.nil? + loged_in_with_france_connect.present? end def invite? dossier_id diff --git a/app/services/switch_devise_profile_service.rb b/app/services/switch_devise_profile_service.rb index dc8d45490..814efac83 100644 --- a/app/services/switch_devise_profile_service.rb +++ b/app/services/switch_devise_profile_service.rb @@ -12,14 +12,14 @@ class SwitchDeviseProfileService private def user_signed_in? - !@warden.authenticate(:scope => :user).nil? + @warden.authenticate(:scope => :user).present? end def gestionnaire_signed_in? - !@warden.authenticate(:scope => :gestionnaire).nil? + @warden.authenticate(:scope => :gestionnaire).present? end def administrateur_signed_in? - !@warden.authenticate(:scope => :administrateur).nil? + @warden.authenticate(:scope => :administrateur).present? end end diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 8f97a445f..73ec2bb2b 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -91,7 +91,7 @@ .col-xs-5.despositaire-info - if type_de_piece_justificative.api_entreprise %span.text-success Nous l'avons récupéré pour vous. - - elsif !(@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).nil? + - elsif (@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).present? %a{ href: "#{@pj.content_url}", target: '_blank' } Consulter %span{ style: 'margin-left: 12px;' } \- diff --git a/app/views/dossiers/_infos_pieces_jointes.html.haml b/app/views/dossiers/_infos_pieces_jointes.html.haml index 05faa1417..ccef97395 100644 --- a/app/views/dossiers/_infos_pieces_jointes.html.haml +++ b/app/views/dossiers/_infos_pieces_jointes.html.haml @@ -29,7 +29,7 @@ .col-xs-6 - if type_de_piece_justificative.api_entreprise %span.text-success Nous l'avons récupéré pour vous. - - elsif !(@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).nil? + - elsif (@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).present? -# - if user_signed_in? -# = 'Pièce fournie' -# - elsif gestionnaire_signed_in? diff --git a/app/views/dossiers/_pieces_justificatives.html.haml b/app/views/dossiers/_pieces_justificatives.html.haml index 2d4427ac9..e5ddebb0d 100644 --- a/app/views/dossiers/_pieces_justificatives.html.haml +++ b/app/views/dossiers/_pieces_justificatives.html.haml @@ -25,7 +25,7 @@ %td.col-lg-6.col-md-6.col-sm-6.col-xs-6 - if type_de_piece_justificative.api_entreprise %span.text-success Nous l'avons récupéré pour vous. - - elsif !(@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).nil? + - elsif (@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).present? -# - if user_signed_in? -# = 'Pièce fournie' -# - elsif gestionnaire_signed_in? diff --git a/lib/tasks/cloud_storage.rake b/lib/tasks/cloud_storage.rake index fc9336a62..878d3acce 100644 --- a/lib/tasks/cloud_storage.rake +++ b/lib/tasks/cloud_storage.rake @@ -44,7 +44,7 @@ namespace :cloudstorage do error_count += 1 end else - if !content.current_path.nil? && File.exist?(File.dirname(content.current_path) + '/uploaded') + if content.current_path.present? && File.exist?(File.dirname(content.current_path) + '/uploaded') filename = File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read secure_token = File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "r").read @@ -52,7 +52,7 @@ namespace :cloudstorage do entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token) puts "RESTORE IN DATABASE: #{filename} " - elsif !content.current_path.nil? + elsif content.current_path.present? puts "Skipping #{content.current_path}" end end