Skip to content

Commit

Permalink
Prefer && and || to "and" and "or"
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 17, 2016
1 parent 5420cd5 commit d9720dc
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 59 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ Style/AlignParameters:
- 'lib/blacklight/configuration.rb'
- 'lib/generators/blacklight/solr4_generator.rb'

# Offense count: 64
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: always, conditionals
Style/AndOr:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ def clear
protected

def verify_user
unless current_or_guest_user or (action == "index" and token_or_current_or_guest_user)
flash[:notice] = I18n.t('blacklight.bookmarks.need_login') and raise Blacklight::Exceptions::AccessDenied
unless current_or_guest_user || (action == "index" && token_or_current_or_guest_user)
flash[:notice] = I18n.t('blacklight.bookmarks.need_login')
raise Blacklight::Exceptions::AccessDenied
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def track
search_session['id'] = params[:search_id]
search_session['per_page'] = params[:per_page]

if params[:redirect] and (params[:redirect].starts_with?('/') or params[:redirect] =~ URI.regexp)
if params[:redirect] && (params[:redirect].starts_with?('/') || params[:redirect] =~ URI.regexp)
path = URI.parse(params[:redirect]).path
redirect_to path, status: 303
else
Expand Down Expand Up @@ -110,7 +110,7 @@ def action_success_redirect_path
# Check if any search parameters have been set
# @return [Boolean]
def has_search_parameters?
!params[:q].blank? or !params[:f].blank? or !params[:search_field].blank?
!params[:q].blank? || !params[:f].blank? || !params[:search_field].blank?
end

protected
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def blacklight_configuration_context
# Determine whether to render the bookmarks control
# (Needs to be available globally, as it is used in the navbar)
def render_bookmarks_control?
has_user_authentication_provider? and current_or_guest_user.present?
has_user_authentication_provider? && current_or_guest_user.present?
end

##
# Determine whether to render the saved searches link
# (Needs to be available globally, as it is used in the navbar)
def render_saved_searches?
has_user_authentication_provider? and current_user
has_user_authentication_provider? && current_user
end

# @return [Blacklight::SearchState] a memoized instance of the parameter state.
Expand Down Expand Up @@ -137,7 +137,7 @@ def require_user_authentication_provider
##
# When a user logs in, transfer any saved searches or bookmarks to the current_user
def transfer_guest_user_actions_to_current_user
return unless respond_to? :current_user and respond_to? :guest_user and current_user and guest_user
return unless respond_to?(:current_user) && respond_to?(:guest_user) && current_user && guest_user
current_user_searches = current_user.searches.pluck(:query_params)
current_user_bookmarks = current_user.bookmarks.pluck(:document_id)

Expand All @@ -162,9 +162,9 @@ def access_denied
# send the user home if the access was previously denied by the same
# request to avoid sending the user back to the login page
# (e.g. protected page -> logout -> returned to protected page -> home)
redirect_to root_url and flash.discard and return if request.referer and request.referer.ends_with? request.fullpath
redirect_to(root_url) && flash.discard && return if request.referer && request.referer.ends_with?(request.fullpath)

redirect_to root_url and return unless has_user_authentication_provider?
redirect_to(root_url) && return unless has_user_authentication_provider?

redirect_to new_user_session_url(:referer => request.fullpath)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/request_builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def facet_limit_for(facet_field)
facet = blacklight_config.facet_fields[facet_field]
return if facet.blank?

if facet.limit and @response and @response.aggregations[facet_field]
if facet.limit && @response && @response.aggregations[facet_field]
limit = @response.aggregations[facet_field].limit

if limit.nil? # we didn't get or a set a limit, so infer one.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/saved_searches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def clear
protected

def verify_user
flash[:notice] = I18n.t('blacklight.saved_searches.need_login') and raise Blacklight::Exceptions::AccessDenied unless current_user
flash[:notice] = I18n.t('blacklight.saved_searches.need_login') && raise(Blacklight::Exceptions::AccessDenied) unless current_user
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def start_new_search_session?
end

def find_or_initialize_search_session_from_params params
params_copy = params.reject { |k,v| blacklisted_search_session_params.include?(k.to_sym) or v.blank? }
params_copy = params.reject { |k,v| blacklisted_search_session_params.include?(k.to_sym) || v.blank? }

return if params_copy.reject { |k,v| [:action, :controller].include? k.to_sym }.blank?

Expand Down Expand Up @@ -94,7 +94,7 @@ def blacklisted_search_session_params
# calls setup_previous_document then setup_next_document.
# used in the show action for single view pagination.
def setup_next_and_previous_documents
if search_session['counter'] and current_search_session
if search_session['counter'] && current_search_session
index = search_session['counter'].to_i - 1
response, documents = get_previous_and_next_documents_for_search index, ActiveSupport::HashWithIndifferentAccess.new(current_search_session.query_params)

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def document_has_value? document, field_config
# @param [Blacklight::Solr::Response] response
# @return [Boolean]
def should_show_spellcheck_suggestions? response
response.total <= spell_check_max and response.spelling.words.any?
response.total <= spell_check_max && response.spelling.words.any?
end

##
Expand Down Expand Up @@ -204,7 +204,7 @@ def render_document_heading(*args)
def document_index_view_type query_params=params
view_param = query_params[:view]
view_param ||= session[:preferred_view]
if view_param and document_index_views.keys.include? view_param.to_sym
if view_param && document_index_views.keys.include?(view_param.to_sym)
view_param.to_sym
else
default_document_index_view_type
Expand Down
16 changes: 8 additions & 8 deletions app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def page_entries_info(collection, options = {})
options[:entry_name]
elsif collection.respond_to? :model # DataMapper
collection.model.model_name.human.downcase
elsif collection.respond_to? :model_name and !collection.model_name.nil? # AR, Blacklight::PaginationMethods
elsif collection.respond_to?(:model_name) && !collection.model_name.nil? # AR, Blacklight::PaginationMethods
collection.model_name.human.downcase
else
t('blacklight.entry_name.default')
Expand All @@ -46,7 +46,7 @@ def page_entries_info(collection, options = {})
entry_name = entry_name.pluralize unless collection.total_count == 1

# grouped response objects need special handling
end_num = if collection.respond_to? :groups and render_grouped_response? collection
end_num = if collection.respond_to?(:groups) && render_grouped_response?(collection)
collection.groups.length
else
collection.limit_value
Expand Down Expand Up @@ -113,15 +113,15 @@ def search_field_label(params)
#
# @return [Blacklight::Configuration::SortField]
def current_sort_field
(blacklight_config.sort_fields.values.find {|f| f.sort == @response.sort} if @response and @response.sort.present?) || blacklight_config.sort_fields[params[:sort]] || default_sort_field
(blacklight_config.sort_fields.values.find {|f| f.sort == @response.sort} if @response && @response.sort.present?) || blacklight_config.sort_fields[params[:sort]] || default_sort_field
end

##
# Look up the current per page value, or the default if none if set
#
# @return [Integer]
def current_per_page
(@response.rows if @response and @response.rows > 0) || params.fetch(:per_page, default_per_page).to_i
(@response.rows if @response && @response.rows > 0) || params.fetch(:per_page, default_per_page).to_i
end

##
Expand Down Expand Up @@ -186,8 +186,8 @@ def show_pagination? response = nil
#
# @return [Boolean]
def should_autofocus_on_search_box?
controller.is_a? Blacklight::Catalog and
action_name == "index" and
controller.is_a?(Blacklight::Catalog) &&
action_name == "index" &&
!has_search_parameters?
end

Expand All @@ -197,7 +197,7 @@ def should_autofocus_on_search_box?
# @param [SolrDocument] document
# @return [Boolean]
def has_thumbnail? document
blacklight_config.view_config(document_index_view_type).thumbnail_method.present? or
blacklight_config.view_config(document_index_view_type).thumbnail_method.present? ||
blacklight_config.view_config(document_index_view_type).thumbnail_field && document.has?(blacklight_config.view_config(document_index_view_type).thumbnail_field)
end

Expand Down Expand Up @@ -273,7 +273,7 @@ def current_bookmarks documents_or_response = nil
##
# Check if the document is in the user's bookmarks
def bookmarked? document
current_bookmarks.any? { |x| x.document_id == document.id and x.document_type == document.class }
current_bookmarks.any? { |x| x.document_id == document.id && x.document_type == document.class }
end

def render_search_to_page_title_filter(facet, values)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def document_index_views
##
# Get the default index view type
def default_document_index_view_type
document_index_views.select { |k,config| config.respond_to? :default and config.default }.keys.first || document_index_views.keys.first
document_index_views.select { |k,config| config.respond_to?(:default) && config.default }.keys.first || document_index_views.keys.first
end

##
Expand Down Expand Up @@ -160,7 +160,7 @@ def document_show_link_field document=nil
##
# Default sort field
def default_sort_field
(active_sort_fields.find { |k,config| config.respond_to? :default and config.default } || active_sort_fields.first).try(:last)
(active_sort_fields.find { |k,config| config.respond_to?(:default) && config.default } || active_sort_fields.first).try(:last)
end

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Blacklight::RenderConstraintsHelperBehavior
# @param [Hash] localized_params query parameters
# @return [Boolean]
def query_has_constraints?(localized_params = params)
!(localized_params[:q].blank? and localized_params[:f].blank?)
!(localized_params[:q].blank? && localized_params[:f].blank?)
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/blacklight/render_partials_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def type_field_to_partial_name(document, display_type)
def document_partial_name(document, base_name = nil)
view_config = blacklight_config.view_config(:show)

display_type = if base_name and view_config.key? :"#{base_name}_display_type_field"
display_type = if base_name && view_config.key?(:"#{base_name}_display_type_field")
document[view_config[:"#{base_name}_display_type_field"]]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def has?(k, *values)
def fetch key, *default
if key? key
self[key]
elsif default.empty? and !block_given?
elsif default.empty? && !block_given?
raise KeyError, "key not found \"#{key}\""
else
(yield(self) if block_given?) || default.first
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/solr/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def more_like_this
end

def has_highlight_field? k
return false if response['highlighting'].blank? or response['highlighting'][self.id].blank?
return false if response['highlighting'].blank? || response['highlighting'][self.id].blank?

response['highlighting'][self.id].key? k.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/blacklight/field_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch

def retrieve_simple
# regular document field
if field_config.default and field_config.default.is_a? Proc
if field_config.default && field_config.default.is_a?(Proc)
document.fetch(field_config.field, &field_config.default)
else
document.fetch(field_config.field, field_config.default)
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def self.blacklight_yml

def self.logger
@logger ||= begin
::Rails.logger if defined? Rails and Rails.respond_to? :logger
::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(context)
# @param [#if,#unless] config an object that responds to if/unless
# @return [Boolean]
def evaluate_if_unless_configuration(config, *args)
return config if config == true or config == false
return config if config == true || config == false

if_value = !config.respond_to?(:if) ||
config.if.nil? ||
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/facet_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def normalize! blacklight_config = nil

super

if self.single and self.tag.blank? and self.ex.blank?
if self.single && self.tag.blank? && self.ex.blank?
self.tag = "#{self.key}_single"
self.ex = "#{self.key}_single"
end
Expand Down
12 changes: 6 additions & 6 deletions lib/blacklight/search_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def reset
end

def url_for_document(doc, options = {})
if respond_to?(:blacklight_config) and
blacklight_config.show.route and
(!doc.respond_to?(:to_model) or doc.to_model.is_a? SolrDocument)
if respond_to?(:blacklight_config) &&
blacklight_config.show.route &&
(!doc.respond_to?(:to_model) || doc.to_model.is_a?(SolrDocument))
route = blacklight_config.show.route.merge(action: :show, id: doc).merge(options)
route[:controller] = params[:controller] if route[:controller] == :current
route
Expand All @@ -56,7 +56,7 @@ def add_facet_params(field, item)

add_facet_param(p, field, item)

if item and item.respond_to?(:fq) and item.fq
if item && item.respond_to?(:fq) && item.fq
Array(item.fq).each do |f, v|
add_facet_param(p, f, v)
end
Expand Down Expand Up @@ -122,7 +122,7 @@ def params_for_search(params_to_merge={}, &block)
yield my_params
end

if my_params[:page] and (my_params[:per_page] != params[:per_page] or my_params[:sort] != params[:sort] )
if my_params[:page] && (my_params[:per_page] != params[:per_page] || my_params[:sort] != params[:sort] )
my_params[:page] = 1
end

Expand Down Expand Up @@ -162,7 +162,7 @@ def add_facet_param(p, field, item)
p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
p[:f][url_field] = (p[:f][url_field] || []).dup

if facet_config.single and p[:f][url_field].present?
if facet_config.single && p[:f][url_field].present?
p[:f][url_field] = []
end

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/solr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def send_and_receive(path, solr_params = {})
solr_response = blacklight_config.response_model.new(res, solr_params, document_model: blacklight_config.document_model, blacklight_config: blacklight_config)

Blacklight.logger.debug("Solr query: #{blacklight_config.http_method} #{path} #{solr_params.to_hash.inspect}")
Blacklight.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
Blacklight.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) && ::BLACKLIGHT_VERBOSE_LOGGING
solr_response
end
rescue Errno::ECONNREFUSED => e
Expand Down
6 changes: 3 additions & 3 deletions lib/blacklight/solr/response/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def facet_field_aggregations
# alias all the possible blacklight config names..
blacklight_config.facet_fields.select { |k,v| v.field == facet_field_name }.each do |key,_|
hash[key] = hash[facet_field_name]
end if blacklight_config and !blacklight_config.facet_fields[facet_field_name]
end if blacklight_config && !blacklight_config.facet_fields[facet_field_name]
end
end

Expand Down Expand Up @@ -210,14 +210,14 @@ def facet_query_aggregations
# a hash of Blacklight::Solr::Response::Facet::FacetField objects
def facet_pivot_aggregations
facet_pivot.each_with_object({}) do |(field_name, values), hash|
next unless blacklight_config and !blacklight_config.facet_fields[field_name]
next unless blacklight_config && !blacklight_config.facet_fields[field_name]

items = values.map do |lst|
construct_pivot_field(lst)
end

# alias all the possible blacklight config names..
blacklight_config.facet_fields.select { |k,v| v.pivot and v.pivot.join(",") == field_name }.each do |key, _|
blacklight_config.facet_fields.select { |k,v| v.pivot && v.pivot.join(",") == field_name }.each do |key, _|
hash[key] = Blacklight::Solr::Response::Facets::FacetField.new key, items
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/solr/response/more_like_this.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Blacklight::Solr::Response::MoreLikeThis
def more_like document
mlt = more_like_this[document.id]
return [] unless mlt and mlt['docs']
return [] unless mlt && mlt['docs']

mlt['docs']
end
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/solr/response/spelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def words
# suggestion => [{ frequency =>, word => }] # for extended results
# suggestion => ['word'] # for non-extended results
orig_freq = term_info['origFreq']
if term_info['suggestion'].first.is_a?(Hash) or suggestions.index("correctlySpelled")
if term_info['suggestion'].first.is_a?(Hash) || suggestions.index("correctlySpelled")
word_suggestions << term_info['suggestion'].map do |suggestion|
suggestion['word'] if suggestion['freq'] > orig_freq
end
Expand Down
Loading

0 comments on commit d9720dc

Please sign in to comment.