diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f55d6dec65..a3107db262 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/app/controllers/concerns/blacklight/default_component_configuration.rb b/app/controllers/concerns/blacklight/default_component_configuration.rb index 5ae33c9095..3a89935bb2 100644 --- a/app/controllers/concerns/blacklight/default_component_configuration.rb +++ b/app/controllers/concerns/blacklight/default_component_configuration.rb @@ -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) diff --git a/app/controllers/concerns/blacklight/request_builders.rb b/app/controllers/concerns/blacklight/request_builders.rb index 14f489f1b5..0b58b5b089 100644 --- a/app/controllers/concerns/blacklight/request_builders.rb +++ b/app/controllers/concerns/blacklight/request_builders.rb @@ -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 diff --git a/app/helpers/blacklight/component_helper_behavior.rb b/app/helpers/blacklight/component_helper_behavior.rb index 49f76ab41f..b0ed7e9f23 100644 --- a/app/helpers/blacklight/component_helper_behavior.rb +++ b/app/helpers/blacklight/component_helper_behavior.rb @@ -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 diff --git a/app/models/concerns/blacklight/document/cache_key.rb b/app/models/concerns/blacklight/document/cache_key.rb index 7ffd13c15a..d52e6c4efe 100644 --- a/app/models/concerns/blacklight/document/cache_key.rb +++ b/app/models/concerns/blacklight/document/cache_key.rb @@ -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 diff --git a/app/models/concerns/blacklight/document/dublin_core.rb b/app/models/concerns/blacklight/document/dublin_core.rb index 007ef7e451..ebf6aa8f84 100644 --- a/app/models/concerns/blacklight/document/dublin_core.rb +++ b/app/models/concerns/blacklight/document/dublin_core.rb @@ -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 diff --git a/app/models/concerns/blacklight/document/email.rb b/app/models/concerns/blacklight/document/email.rb index b4847761ef..c5781c7973 100644 --- a/app/models/concerns/blacklight/document/email.rb +++ b/app/models/concerns/blacklight/document/email.rb @@ -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? diff --git a/app/models/concerns/blacklight/document/extensions.rb b/app/models/concerns/blacklight/document/extensions.rb index 2ffac3ba4c..25e9623177 100644 --- a/app/models/concerns/blacklight/document/extensions.rb +++ b/app/models/concerns/blacklight/document/extensions.rb @@ -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 diff --git a/app/models/concerns/blacklight/document/sms.rb b/app/models/concerns/blacklight/document/sms.rb index 21cba38ca2..2cf07d9312 100644 --- a/app/models/concerns/blacklight/document/sms.rb +++ b/app/models/concerns/blacklight/document/sms.rb @@ -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? diff --git a/app/models/concerns/blacklight/solr/document.rb b/app/models/concerns/blacklight/solr/document.rb index 1e9c85ec06..d44af669bb 100644 --- a/app/models/concerns/blacklight/solr/document.rb +++ b/app/models/concerns/blacklight/solr/document.rb @@ -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 diff --git a/app/models/search.rb b/app/models/search.rb index a6cf0ea785..6c4469c5c7 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -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 diff --git a/lib/blacklight/configuration.rb b/lib/blacklight/configuration.rb index 245eddb1b6..5897ebdcbd 100644 --- a/lib/blacklight/configuration.rb +++ b/lib/blacklight/configuration.rb @@ -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. diff --git a/lib/blacklight/configuration/facet_field.rb b/lib/blacklight/configuration/facet_field.rb index 904e1d8b90..5222652887 100644 --- a/lib/blacklight/configuration/facet_field.rb +++ b/lib/blacklight/configuration/facet_field.rb @@ -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 diff --git a/lib/blacklight/configuration/field.rb b/lib/blacklight/configuration/field.rb index ae1c6235d9..a61ab212e6 100644 --- a/lib/blacklight/configuration/field.rb +++ b/lib/blacklight/configuration/field.rb @@ -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 diff --git a/lib/blacklight/configuration/fields.rb b/lib/blacklight/configuration/fields.rb index de842153db..2450acc053 100644 --- a/lib/blacklight/configuration/fields.rb +++ b/lib/blacklight/configuration/fields.rb @@ -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 diff --git a/lib/blacklight/configuration/search_field.rb b/lib/blacklight/configuration/search_field.rb index 829b6431f4..bf113878bd 100644 --- a/lib/blacklight/configuration/search_field.rb +++ b/lib/blacklight/configuration/search_field.rb @@ -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 @@ -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 diff --git a/lib/blacklight/configuration/sort_field.rb b/lib/blacklight/configuration/sort_field.rb index 3c79028806..58f31b4b10 100644 --- a/lib/blacklight/configuration/sort_field.rb +++ b/lib/blacklight/configuration/sort_field.rb @@ -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 diff --git a/lib/blacklight/search_builder.rb b/lib/blacklight/search_builder.rb index 7910a96921..0c22c5e460 100644 --- a/lib/blacklight/search_builder.rb +++ b/lib/blacklight/search_builder.rb @@ -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 diff --git a/lib/blacklight/solr/response.rb b/lib/blacklight/solr/response.rb index fc33fec924..c78885b403 100644 --- a/lib/blacklight/solr/response.rb +++ b/lib/blacklight/solr/response.rb @@ -74,7 +74,7 @@ def group key end def grouped? - self.key? "grouped" + key? "grouped" end def export_formats diff --git a/lib/blacklight/solr/response/spelling.rb b/lib/blacklight/solr/response/spelling.rb index 10b3575140..5781ea22f5 100644 --- a/lib/blacklight/solr/response/spelling.rb +++ b/lib/blacklight/solr/response/spelling.rb @@ -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? @@ -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] diff --git a/lib/blacklight/utils.rb b/lib/blacklight/utils.rb index 517954d7e9..71e86163c7 100644 --- a/lib/blacklight/utils.rb +++ b/lib/blacklight/utils.rb @@ -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 @@ -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 diff --git a/lib/blacklight/version.rb b/lib/blacklight/version.rb index bed58af371..94a5da68c6 100644 --- a/lib/blacklight/version.rb +++ b/lib/blacklight/version.rb @@ -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