Skip to content

Commit

Permalink
enforce coding convention
Browse files Browse the repository at this point in the history
replaced every `and` by `&&` and every `or` by `||`
  • Loading branch information
ZogStriP committed Mar 5, 2013
1 parent f544e1d commit 239cbd2
Show file tree
Hide file tree
Showing 39 changed files with 75 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/export_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Admin::ExportController < Admin::AdminController
def create
unless Export.is_export_running? or Import.is_import_running?
unless Export.is_export_running? || Import.is_import_running?
job_id = Jobs.enqueue( :exporter, user_id: current_user.id )
render json: success_json.merge( job_id: job_id )
else
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def check_restricted_access
end

def mini_profiler_enabled?
defined?(Rack::MiniProfiler) and current_user.try(:admin?)
defined?(Rack::MiniProfiler) && current_user.try(:admin?)
end

def authorize_mini_profiler
Expand All @@ -250,8 +250,7 @@ def store_incoming_links

def check_xhr
unless (controller_name == 'forums' || controller_name == 'user_open_ids')
# render 'default/empty' unless ((request.format && request.format.json?) or request.xhr?)
raise RenderEmpty.new unless ((request.format && request.format.json?) or request.xhr?)
raise RenderEmpty.new unless ((request.format && request.format.json?) || request.xhr?)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/clicks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ClicksController < ApplicationController

def track
requires_parameter(:url)
if params[:topic_id].present? or params[:post_id].present?
if params[:topic_id].present? || params[:post_id].present?
args = {url: params[:url], ip: request.remote_ip}
args[:user_id] = current_user.id if current_user.present?
args[:post_id] = params[:post_id].to_i if params[:post_id].present?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def unsubscribe
@user = User.find_by_temporary_key(params[:key])

# Don't allow the use of a key while logged in as a different user
@user = nil if current_user.present? and (@user != current_user)
@user = nil if current_user.present? && (@user != current_user)

if @user.present?
@user.update_column(:email_digests, false)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/list_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ListController < ApplicationController
list_opts = {page: params[:page]}

# html format means we need to farm exclude from the site options
if params[:format].blank? or params[:format] == "html"
if params[:format].blank? || params[:format] == "html"
#TODO objectify this stuff
SiteSetting.top_menu.split('|').each do |f|
s = f.split(",")
Expand All @@ -35,7 +35,7 @@ def category
list = nil

# If they choose uncategorized, return topics NOT in a category
if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name
if params[:category] == Slug.for(SiteSetting.uncategorized_name) || params[:category] == SiteSetting.uncategorized_name
list = query.list_uncategorized
else
@category = Category.where("slug = ? or id = ?", params[:category], params[:category].to_i).includes(:featured_users).first
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/post_actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create

post_action = PostAction.act(current_user, @post, action.id, params[:message])

if post_action.blank? or post_action.errors.present?
if post_action.blank? || post_action.errors.present?
render_json_error(post_action)
else
# We need to reload or otherwise we are showing the old values on the front end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
if @user.present?

# If the site requires user approval and the user is not approved yet
if SiteSetting.must_approve_users? and !@user.approved?
if SiteSetting.must_approve_users? && !@user.approved?
render :json => {error: I18n.t("login.not_approved")}
return
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
create_topic_view

anonymous_etag(@topic_view.topic) do
redirect_to_correct_topic and return if slugs_do_not_match
redirect_to_correct_topic && return if slugs_do_not_match
View.create_for(@topic_view.topic, request.remote_ip, current_user)
track_visit_to_topic
perform_show_response
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def create_or_sign_on_user_using_openid(auth_token)
user = user_open_id.user

# If we have to approve users
if SiteSetting.must_approve_users? and !user.approved?
if SiteSetting.must_approve_users? && !user.approved?
@data = {awaiting_approval: true}
else
log_on_user(user)
Expand Down Expand Up @@ -222,7 +222,7 @@ def create_or_sign_on_user_using_persona(auth_token)
user = User.find_by_email(email)

if user
if SiteSetting.must_approve_users? and !user.approved?
if SiteSetting.must_approve_users? && !user.approved?
@data = {awaiting_approval: true}
else
log_on_user(user)
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def check_username
else

# Contact the Discourse Hub server
email_given = (params[:email].present? or current_user.present?)
email_given = (params[:email].present? || current_user.present?)
available_locally = User.username_available?(params[:username])
global_match = false
available_globally, suggestion_from_discourse_hub = begin
Expand All @@ -101,9 +101,9 @@ def check_username
end
end

if available_globally and available_locally
if available_globally && available_locally
render json: {available: true, global_match: (global_match ? true : false)}
elsif available_locally and !available_globally
elsif available_locally && !available_globally
if email_given
# Nickname and email do not match what's registered on the discourse hub.
render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub}
Expand All @@ -113,7 +113,7 @@ def check_username
# Don't give a suggestion until we get the email and try to match it with on the discourse hub.
render json: {available: false}
end
elsif available_globally and !available_locally
elsif available_globally && !available_locally
# Already registered on this site with the matching nickname and email address. Why are you signing up again?
render json: {available: false, suggestion: User.suggest_username(params[:username])}
else
Expand All @@ -128,7 +128,7 @@ def check_username

def create

if params[:password_confirmation] != honeypot_value or params[:challenge] != challenge_value.try(:reverse)
if params[:password_confirmation] != honeypot_value || params[:challenge] != challenge_value.try(:reverse)
# Don't give any indication that we caught you in the honeypot
return render(:json => {success: true, active: false, message: I18n.t("login.activate_email", email: params[:email]) })
end
Expand All @@ -145,7 +145,7 @@ def create
end
user.password_required! unless auth

DiscourseHub.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_discourse_hub?
DiscourseHub.register_nickname( user.username, user.email ) if user.valid? && SiteSetting.call_discourse_hub?

if user.save

Expand Down Expand Up @@ -174,7 +174,7 @@ def create
TwitterUserInfo.create(:user_id => user.id, :screen_name => auth[:twitter_screen_name], :twitter_user_id => auth[:twitter_user_id])
end

if auth[:facebook].present? and FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil?
if auth[:facebook].present? && FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil?
FacebookUserInfo.create!(auth[:facebook].merge(user_id: user.id))
end

Expand Down Expand Up @@ -232,11 +232,11 @@ def password_reset
if @user.blank?
flash[:error] = I18n.t('password_reset.no_token')
else
if request.put? and params[:password].present?
if request.put? && params[:password].present?
@user.password = params[:password]
if @user.save

if SiteSetting.must_approve_users? and !@user.approved?
if SiteSetting.must_approve_users? && !@user.approved?
@requires_approval = true
flash[:success] = I18n.t('password_reset.success_unapproved')
else
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def guardian
end

def mini_profiler_enabled?
defined?(Rack::MiniProfiler) and admin?
defined?(Rack::MiniProfiler) && admin?
end

def admin?
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def digest(user, opts={})
@markdown_linker = MarkdownLinker.new(Discourse.base_url)

# Don't send email unless there is content in it
if @new_topics.present? or @notifications.present?
if @new_topics.present? || @notifications.present?
mail to: user.email,
subject: I18n.t('user_notifications.digest.subject_template',
:site_name => @site_name,
Expand Down
2 changes: 1 addition & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def filter_quotes(parent_post = nil)

parent_raw = parent_post.raw.sub(/\[quote.+\/quote\]/m, '')

if raw[parent_raw] or (parent_raw.size < SHORT_POST_CHARS)
if raw[parent_raw] || (parent_raw.size < SHORT_POST_CHARS)
return cooked.sub(/\<aside.+\<\/aside\>/m, '')
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/post_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def message_quality
end

before_create do
raise AlreadyFlagged if is_flag? and PostAction.where(user_id: user_id,
post_id: post_id,
post_action_type_id: PostActionType.flag_types.values).exists?
raise AlreadyFlagged if is_flag? && PostAction.where(user_id: user_id,
post_id: post_id,
post_action_type_id: PostActionType.flag_types.values).exists?
end

after_save do
Expand Down
2 changes: 1 addition & 1 deletion app/models/site_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class SiteSetting < ActiveRecord::Base
client_setting(:educate_until_posts, 2)

def self.call_discourse_hub?
self.enforce_global_nicknames? and self.discourse_org_access_key.present?
self.enforce_global_nicknames? && self.discourse_org_access_key.present?
end

def self.topic_title_length
Expand Down
4 changes: 2 additions & 2 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def changed_to_category(cat)
Topic.transaction do
old_category = category

if category_id.present? and category_id != cat.id
if category_id.present? && category_id != cat.id
Category.update_all 'topic_count = topic_count - 1', ['id = ?', category_id]
end

Expand Down Expand Up @@ -444,7 +444,7 @@ def posters_summary(topic_user = nil, current_user = nil, opts={})
end
end

posted = if topic_user.present? and current_user.present?
posted = if topic_user.present? && current_user.present?
current_user if topic_user.posted?
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def email_validator
end

def password_validator
if (@raw_password and @raw_password.length < 6) || (@password_required && !@raw_password)
if (@raw_password && @raw_password.length < 6) || (@password_required && !@raw_password)
errors.add(:password, "must be 6 letters or longer")
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/serializers/post_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ def actions_summary
can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}

# The following only applies if you're logged in
if action_summary[:can_act] and scope.current_user.present?
if action_summary[:can_act] && scope.current_user.present?
action_summary[:can_clear_flags] = scope.is_admin? && PostActionType.flag_types.values.include?(id)

if post_actions.present? and post_actions.has_key?(id)
if post_actions.present? && post_actions.has_key?(id)
action_summary[:acted] = true
action_summary[:can_undo] = scope.can_delete?(post_actions[id])
end
Expand Down Expand Up @@ -188,19 +188,19 @@ def include_raw?
def include_link_counts?
return true if @single_post_link_counts.present?

@topic_view.present? and @topic_view.link_counts.present? and @topic_view.link_counts[object.id].present?
@topic_view.present? && @topic_view.link_counts.present? && @topic_view.link_counts[object.id].present?
end

def include_read?
@topic_view.present?
end

def include_reply_to_user?
object.quoteless? and object.reply_to_user
object.quoteless? && object.reply_to_user
end

def include_bookmarked?
post_actions.present? and post_actions.keys.include?(PostActionType.types[:bookmark])
post_actions.present? && post_actions.keys.include?(PostActionType.types[:bookmark])
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/topic_list_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def can_create_topic
end

def include_more_topics_url?
object.more_topics_url.present? and (object.topics.size == SiteSetting.topics_per_page)
object.more_topics_url.present? && (object.topics.size == SiteSetting.topics_per_page)
end

end
6 changes: 3 additions & 3 deletions app/serializers/topic_view_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ def participants
end

def include_participants?
object.initial_load? and object.posts_count.present?
object.initial_load? && object.posts_count.present?
end

def suggested_topics
object.suggested_topics.topics
end
def include_suggested_topics?
at_bottom and object.suggested_topics.present?
at_bottom && object.suggested_topics.present?
end

# Whether we're at the bottom of a topic (last page)
def at_bottom
posts.present? and (@highest_number_in_posts == object.highest_post_number)
posts.present? && (@highest_number_in_posts == object.highest_post_number)
end

def highest_post_number
Expand Down
16 changes: 8 additions & 8 deletions config/initializers/mini_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

# For our app, let's just show mini profiler always, polling is chatty so nuke that
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) and
(env['PATH_INFO'] !~ /^\/message-bus/) and
(env['PATH_INFO'] !~ /topics\/timings/) and
(env['PATH_INFO'] !~ /assets/) and
(env['PATH_INFO'] !~ /jasmine/) and
(env['PATH_INFO'] !~ /users\/.*\/avatar/) and
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) &&
(env['PATH_INFO'] !~ /^\/message-bus/) &&
(env['PATH_INFO'] !~ /topics\/timings/) &&
(env['PATH_INFO'] !~ /assets/) &&
(env['PATH_INFO'] !~ /jasmine/) &&
(env['PATH_INFO'] !~ /users\/.*\/avatar/) &&
(env['PATH_INFO'] !~ /srv\/status/)
end

Expand All @@ -27,15 +27,15 @@
inst = Class.new
class << inst
def start(name,id,payload)
if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/
if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
@prf ||= {}
@prf[id] ||= []
@prf[id] << Rack::MiniProfiler.start_step("#{payload[:serializer] if name =~ /serialize.serializer/} #{name}")
end
end

def finish(name,id,payload)
if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/
if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
t = @prf[id].pop
@prf.delete id unless t
Rack::MiniProfiler.finish_step t
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$redis = DiscourseRedis.new

if Rails.env.development? and !ENV['DO_NOT_FLUSH_REDIS']
if Rails.env.development? && !ENV['DO_NOT_FLUSH_REDIS']
puts "Flushing redis (development mode)"
$redis.flushall
end
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/verify_config.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Check that the app is configured correctly. Raise some helpful errors if something is wrong.

if Rails.env.production? and ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
if Rails.env.production? && ['localhost', 'production.localhost'].include?(Discourse.current_hostname)
puts <<END
Discourse.current_hostname = '#{Discourse.current_hostname}'
Please update the host_names property in config/database.yml
so that it uses the hostname of your site. Otherwise you will
so that it uses the hostname of your site. Otherwise you will
experience problems, like links in emails using #{Discourse.current_hostname}.
END
Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_iife.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def evaluate(context, locals)
path = context.pathname.to_s

# Only discourse or admin paths
return data unless (path =~ /\/javascripts\/discourse/ or path =~ /\/javascripts\/admin/)
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/)

# Ugh, ignore translations
return data if (path =~ /\/translations/)
Expand Down
Loading

0 comments on commit 239cbd2

Please sign in to comment.