Skip to content

Commit

Permalink
Remove redundant 'self'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored and atz committed Dec 8, 2016
1 parent 907f1da commit aa46620
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 46 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,3 @@ Style/PredicateName:
- 'app/models/concerns/blacklight/document.rb'
- 'app/models/concerns/blacklight/solr/document.rb'
- 'lib/generators/blacklight/assets_generator.rb'

# Offense count: 43
# Cop supports --auto-correct.
Style/RedundantSelf:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def add_show_tools_partial(name, opts = {})
@response, @documents = action_documents

if request.post? && opts[:callback] &&
(opts[:validator].blank? || self.send(opts[:validator]))
(opts[:validator].blank? || send(opts[:validator]))

self.send(opts[:callback], @documents)
send(opts[:callback], @documents)

flash[:success] ||= I18n.t("blacklight.#{name}.success", default: nil)

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 @@ -4,7 +4,7 @@ module RequestBuilders
extend ActiveSupport::Concern

included do
if self.respond_to?(:helper_method)
if respond_to?(:helper_method)
helper_method(:facet_limit_for)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/component_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def document_action_label action, opts

def document_action_path action_opts, url_opts = nil
if action_opts.path
self.send(action_opts.path, url_opts)
send(action_opts.path, url_opts)
elsif url_opts[:id].class.respond_to?(:model_name)
url_for([action_opts.key, url_opts[:id]])
else
self.send("#{action_opts.key}_#{controller_name}_path", url_opts)
send("#{action_opts.key}_#{controller_name}_path", url_opts)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/cache_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Blacklight::Document::CacheKey
def cache_key
if new_record?
"#{self.class.model_name.cache_key}/new"
elsif self.key? cache_version_key
elsif key? cache_version_key
cache_version_value = self[cache_version_key]
"#{self.class.model_name.cache_key}/#{id}-#{Array(cache_version_value).join}"
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/dublin_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def export_as_oai_dc_xml
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xsi:schemaLocation' => %(http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd)) do
self.to_semantic_values.select { |field, _values| dublin_core_field_name? field }.each do |field, values|
to_semantic_values.select { |field, _values| dublin_core_field_name? field }.each do |field, values|
Array.wrap(values).each do |v|
xml.tag! "dc:#{field}", v
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight::Document::Email
# Return a text string that will be the body of the email
def to_email_text
semantics = self.to_semantic_values
semantics = to_semantic_values
body = []
body << I18n.t('blacklight.email.text.title', value: semantics[:title].join(" ")) unless semantics[:title].blank?
body << I18n.t('blacklight.email.text.author', value: semantics[:author].join(" ")) unless semantics[:author].blank?
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Blacklight::Document::Extensions
# apply all registered extensions on a per-document basis
def apply_extensions
self.class.registered_extensions.each do |registration|
self.extend(registration[:module_obj]) if registration[:condition_proc].nil? || registration[:condition_proc].call(self)
extend(registration[:module_obj]) if registration[:condition_proc].nil? || registration[:condition_proc].call(self)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight::Document::Sms
# Return a text string that will be the body of the email
def to_sms_text
semantics = self.to_semantic_values
semantics = to_semantic_values
body = []
body << I18n.t('blacklight.sms.text.title', value: semantics[:title].first) unless semantics[:title].blank?
body << I18n.t('blacklight.sms.text.author', value: semantics[:author].first) unless semantics[:author].blank?
Expand Down
7 changes: 3 additions & 4 deletions app/models/concerns/blacklight/solr/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ def more_like_this
end

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

response['highlighting'][self.id].key? k.to_s
return false if response['highlighting'].blank? || response['highlighting'][id].blank?
response['highlighting'][id].key? k.to_s
end

def highlight_field k
response['highlighting'][self.id][k.to_s].map(&:html_safe) if has_highlight_field? k
response['highlighting'][id][k.to_s].map(&:html_safe) if has_highlight_field? k
end
end
4 changes: 2 additions & 2 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Search < ActiveRecord::Base

# A Search instance is considered a saved search if it has a user_id.
def saved?
self.user_id?
user_id?
end

# delete old, unsaved searches
def self.delete_old_searches(days_old)
raise ArgumentError, 'days_old is expected to be a number' unless days_old.is_a?(Numeric)
raise ArgumentError, 'days_old is expected to be greater than 0' if days_old <= 0
self.where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).destroy_all
where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).destroy_all
end
end
2 changes: 1 addition & 1 deletion lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def deep_copy
# @param [Symbol,#to_sym] view_type
def view_config(view_type)
view_type = view_type.to_sym unless view_type.is_a? Symbol
self.index.merge(view_type == :show ? self.show : view.fetch(view_type, {}))
index.merge(view_type == :show ? show : view.fetch(view_type, {}))
end

# YARD will include inline disabling as docs, cannot do multiline inside @!macro. AND this must be separate from doc block.
Expand Down
20 changes: 10 additions & 10 deletions lib/blacklight/configuration/facet_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ class Configuration::FacetField < Blacklight::Configuration::Field
extend Deprecation

def normalize! blacklight_config = nil
self.query.stringify_keys! if self.query
query.stringify_keys! if query

self.collapse = true if self.collapse.nil?
self.show = true if self.show.nil?
self.if = self.show if self.if.nil?
self.index_range = 'A'..'Z' if self.index_range == true
self.collapse = true if collapse.nil?
self.show = true if show.nil?
self.if = show if self.if.nil?
self.index_range = 'A'..'Z' if index_range == true

if self.link_to_search
if link_to_search
Deprecation.warn(Blacklight::Configuration::FacetField, '`link_to_search:` is deprecated, use `link_to_facet:` instead')
self.link_to_facet = self.link_to_search if self.link_to_facet.nil?
self.link_to_facet = link_to_search if link_to_facet.nil?
end

super

if self.single && self.tag.blank? && self.ex.blank?
self.tag = "#{self.key}_single"
self.ex = "#{self.key}_single"
if single && tag.blank? && ex.blank?
self.tag = "#{key}_single"
self.ex = "#{key}_single"
end

self
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Blacklight
class Configuration::Field < OpenStructWithHashAccess
def normalize! _blacklight_config = nil
self.field ||= self.key
self.field ||= key
self.key ||= self.field

self.label ||= default_label
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/configuration/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module ClassMethods
def define_field_access(key, options = {})
key = key.to_s if respond_to? :to_s

self.default_values[key.pluralize.to_sym] = ActiveSupport::OrderedHash.new
default_values[key.pluralize.to_sym] = ActiveSupport::OrderedHash.new

base_class_name = options.fetch(:class, Field)

unless self.const_defined? key.camelcase
unless const_defined? key.camelcase
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
class #{key.camelcase} < #{base_class_name}; end
END_EVAL
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/configuration/search_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Blacklight
class Configuration::SearchField < Blacklight::Configuration::Field
def normalize! blacklight_config = nil
self.if = self.include_in_simple_select if self.if.nil?
self.if = include_in_simple_select if self.if.nil?

super
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
Expand All @@ -11,7 +11,7 @@ def normalize! blacklight_config = nil
end

def validate!
raise ArgumentError, "Must supply a search field key" if self.key.nil?
raise ArgumentError, "Must supply a search field key" if key.nil?
end
end
end
4 changes: 2 additions & 2 deletions lib/blacklight/configuration/sort_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Blacklight
class Configuration::SortField < Blacklight::Configuration::Field
def normalize! blacklight_config = nil
super
self.field ||= self.label.try(:parameterize)
self.field ||= self.sort
self.field ||= label.try(:parameterize)
self.field ||= sort

self.sort ||= self.field

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def to_hash
@params = processed_parameters.
reverse_merge(@reverse_merged_params).
merge(@merged_params).
tap { self.clear_changes }
tap { clear_changes }
end

alias_method :query, :to_hash
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/solr/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def group key
end

def grouped?
self.key? "grouped"
key? "grouped"
end

def export_formats
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/solr/response/spelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(response)
def words
@words ||= begin
word_suggestions = []
spellcheck = self.response[:spellcheck]
spellcheck = response[:spellcheck]
if spellcheck && spellcheck[:suggestions]
suggestions = spellcheck[:suggestions]
unless suggestions.nil?
Expand Down Expand Up @@ -74,7 +74,7 @@ def words

def collation
# FIXME: DRY up with words
spellcheck = self.response[:spellcheck]
spellcheck = response[:spellcheck]
return unless spellcheck && spellcheck[:suggestions]
suggestions = spellcheck[:suggestions]

Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def marshal_load x
end

def deep_dup
self.class.new self.nested_class, @table.deep_dup
self.class.new nested_class, @table.deep_dup
end

def select *args, &block
Expand Down Expand Up @@ -156,7 +156,7 @@ def method_missing(mid, *args)

def set_default_proc!
self.default_proc = lambda do |hash, key|
hash[key] = self.nested_class.new
hash[key] = nested_class.new
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def self.version
@version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
end

VERSION = self.version
VERSION = version
end
end

0 comments on commit aa46620

Please sign in to comment.