From f003f7e8ef818d1ceab66530c0c41cc0b3909716 Mon Sep 17 00:00:00 2001 From: Pieter Nicolai Date: Fri, 4 Mar 2011 01:05:29 +0100 Subject: [PATCH] Replace if! with unless where it improves readability --- app/controllers/application_controller.rb | 8 ++++---- app/controllers/messages_controller.rb | 2 +- app/controllers/search_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/helpers/journals_helper.rb | 16 +++++++++++----- app/helpers/repositories_helper.rb | 7 +++---- app/models/auth_source_ldap.rb | 2 +- app/models/changeset.rb | 2 +- app/models/user.rb | 2 +- app/views/context_menus/issues.html.erb | 2 +- app/views/projects/show.rhtml | 6 +++--- app/views/users/show.rhtml | 6 +++--- app/views/versions/_overview.rhtml | 2 +- lib/redmine/about.rb | 2 +- lib/redmine/scm/adapters/git_adapter.rb | 2 +- lib/tasks/migrate_from_trac.rake | 2 +- 16 files changed, 35 insertions(+), 30 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 803eb5f..2bf2cab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -109,7 +109,7 @@ class ApplicationController < ActionController::Base end if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first - if !accept_lang.blank? + unless accept_lang.blank? accept_lang = accept_lang.downcase lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) end @@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base end def require_login - if !User.current.logged? + unless User.current.logged? # Extract only the basic url parameters on non-GET requests if request.get? url = url_for(params) @@ -140,7 +140,7 @@ class ApplicationController < ActionController::Base def require_admin return unless require_login - if !User.current.admin? + unless User.current.admin? render_403 return false end @@ -258,7 +258,7 @@ class ApplicationController < ActionController::Base def redirect_back_or_default(default) back_url = CGI.unescape(params[:back_url].to_s) - if !back_url.blank? + unless back_url.blank? begin uri = URI.parse(back_url) # do not redirect user to another host or to the login or register page diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 5ad8ea5..0ef3586 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -74,7 +74,7 @@ class MessagesController < ApplicationController @reply.author = User.current @reply.board = @board @topic.children << @reply - if !@reply.new_record? + unless @reply.new_record? call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f2e146b..bb4c734 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -65,7 +65,7 @@ class SearchController < ApplicationController # tokens must be at least 2 characters long @tokens = @tokens.uniq.select {|w| w.length > 1 } - if !@tokens.empty? + unless @tokens.empty? # no more than 5 tokens to search for @tokens.slice! 5..-1 if @tokens.size > 5 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index be0ebae..01feb3f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -484,7 +484,7 @@ module ApplicationHelper s = StringScanner.new(text) tags = [] parsed = '' - while !s.eos? + until s.eos? s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im) text, full_tag, closing, tag = s[1], s[2], s[3], s[4] if tags.empty? diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index c8d53f2..a97add9 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -20,13 +20,19 @@ module JournalsHelper content = '' editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project))) links = [] - if !journal.notes.blank? + unless journal.notes.blank? links << link_to_remote(image_tag('comment.png'), - { :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} }, + { :url => { :controller => 'journals', + :action => 'new', + :id => issue, + :journal_id => journal} }, :title => l(:button_quote)) if options[:reply_links] - links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes", - { :controller => 'journals', :action => 'edit', :id => journal }, - :title => l(:button_edit)) if editable + links << link_to_in_place_notes_editor(image_tag('edit.png'), + "journal-#{journal.id}-notes", + { :controller => 'journals', + :action => 'edit', + :id => journal }, + :title => l(:button_edit)) if editable end content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty? content << textilizable(journal, :notes) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 1ae1346..83fc165 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -47,7 +47,7 @@ module RepositoriesHelper case change.action when 'A' # Detects moved/copied files - if !change.from_path.blank? + unless change.from_path.blank? change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' end change @@ -141,9 +141,8 @@ module RepositoriesHelper def replace_invalid_utf8(str) if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') - if ! str.valid_encoding? - str = str.encode("US-ASCII", :invalid => :replace, - :undef => :replace, :replace => '?').encode("UTF-8") + unless str.valid_encoding? + str = str.encode("US-ASCII", :invalid => :replace, :undef => :replace, :replace => '?').encode("UTF-8") end end str diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index 6b23c67..6f99d45 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -123,7 +123,7 @@ class AuthSourceLdap < AuthSource end def self.get_attr(entry, attr_name) - if !attr_name.blank? + unless attr_name.blank? entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name] end end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index c4f1f3f..1e2f521 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -255,7 +255,7 @@ class Changeset < ActiveRecord::Base end if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') - if ! str.valid_encoding? + unless str.valid_encoding? str = str.encode("US-ASCII", :invalid => :replace, :undef => :replace, :replace => '?').encode("UTF-8") end diff --git a/app/models/user.rb b/app/models/user.rb index 0259768..29b3c13 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -117,7 +117,7 @@ class User < Principal user = find_by_login(login) if user # user is already in local database - return nil if !user.active? + return nil unless user.active? if user.auth_source # user has an external authentication method return nil unless user.auth_source.authenticate(login, password) diff --git a/app/views/context_menus/issues.html.erb b/app/views/context_menus/issues.html.erb index f0fa350..4a775c2 100644 --- a/app/views/context_menus/issues.html.erb +++ b/app/views/context_menus/issues.html.erb @@ -96,7 +96,7 @@ <% end %> -<% if !@issue.nil? %> +<% unless @issue.nil? %> <% if @can[:log_time] -%>
  • <%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'new', :issue_id => @issue}, :class => 'icon-time-add' %>
  • diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml index 414358a..c8098e1 100644 --- a/app/views/projects/show.rhtml +++ b/app/views/projects/show.rhtml @@ -17,9 +17,9 @@ <%= @subprojects.collect{|p| link_to(h(p), :action => 'show', :id => p)}.join(", ") %> <% end %> <% @project.visible_custom_field_values.each do |custom_value| %> - <% if !custom_value.value.blank? %> -
  • <%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %>
  • - <% end %> + <% unless custom_value.value.blank? %> +
  • <%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %>
  • + <% end %> <% end %> diff --git a/app/views/users/show.rhtml b/app/views/users/show.rhtml index c100e6e..f5dd9eb 100644 --- a/app/views/users/show.rhtml +++ b/app/views/users/show.rhtml @@ -10,9 +10,9 @@
  • <%=l(:field_mail)%>: <%= mail_to(h(@user.mail), nil, :encode => 'javascript') %>
  • <% end %> <% @user.visible_custom_field_values.each do |custom_value| %> - <% if !custom_value.value.blank? %> -
  • <%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %>
  • - <% end %> + <% unless custom_value.value.blank? %> +
  • <%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %>
  • + <% end %> <% end %>
  • <%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %>
  • <% unless @user.last_login_on.nil? %> diff --git a/app/views/versions/_overview.rhtml b/app/views/versions/_overview.rhtml index 550cf3e..264b262 100644 --- a/app/views/versions/_overview.rhtml +++ b/app/views/versions/_overview.rhtml @@ -7,7 +7,7 @@

    <%=h version.description %>