File algoliasearch-rails.rb
has 847 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'algolia'
require 'algoliasearch/version'
require 'algoliasearch/utilities'
Method algoliasearch
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
def algoliasearch(options = {}, &block)
self.algoliasearch_settings = IndexSettings.new(options, &block)
self.algoliasearch_options = { :type => algolia_full_const_get(model_name.to_s), :per_page => algoliasearch_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options)
attr_accessor :highlight_result, :snippet_result
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method extended
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def self.extended(base)
class <<base
alias_method :without_auto_index, :algolia_without_auto_index unless method_defined? :without_auto_index
alias_method :reindex!, :algolia_reindex! unless method_defined? :reindex!
alias_method :reindex, :algolia_reindex unless method_defined? :reindex
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algoliasearch
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
def algoliasearch(options = {}, &block)
self.algoliasearch_settings = IndexSettings.new(options, &block)
self.algoliasearch_options = { :type => algolia_full_const_get(model_name.to_s), :per_page => algoliasearch_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options)
attr_accessor :highlight_result, :snippet_result
Method algolia_index!
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def algolia_index!(object, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
object_id = algolia_object_id_of(object, options)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_reindex
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
next if options[:replica]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_reindex!
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def algolia_reindex!(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
index = algolia_ensure_init(options, settings)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_must_reindex?
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def algolia_must_reindex?(object)
# use +algolia_dirty?+ method if implemented
return object.send(:algolia_dirty?) if (object.respond_to?(:algolia_dirty?))
# Loop over each index to see if a attribute used in records has changed
algolia_configurations.each do |options, settings|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_ensure_init
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def algolia_ensure_init(options = nil, settings = nil, index_settings = nil)
raise ArgumentError.new('No `algoliasearch` block found in your model.') if algoliasearch_settings.nil?
@algolia_indexes ||= {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algoliasearch_settings_changed?
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def algoliasearch_settings_changed?(prev, current)
return true if prev.nil?
current.each do |k, v|
prev_v = prev[k.to_s]
if v.is_a?(Array) and prev_v.is_a?(Array)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_remove_from_index!
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def algolia_remove_from_index!(object, synchronous = false)
return if algolia_without_auto_index_scope
object_id = algolia_object_id_of(object)
raise ArgumentError.new("Cannot index a record with a blank objectID") if object_id.blank?
algolia_configurations.each do |options, settings|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_reindex
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
return if algolia_without_auto_index_scope
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
next if options[:replica]
Method algolia_find_in_batches
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def algolia_find_in_batches(batch_size, &block)
if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
find_in_batches(:batch_size => batch_size, &block)
elsif defined?(::Sequel) && defined?(::Sequel::Model) && self < Sequel::Model
dataset.extension(:pagination).each_page(batch_size, &block)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method to_settings
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def to_settings
settings = {}
OPTIONS.each do |k|
v = get_setting(k)
settings[k] = v if !v.nil?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_search
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def algolia_search(q, params = {})
if AlgoliaSearch.configuration[:pagination_backend]
# kaminari, will_paginate, and pagy start pagination at 1, Algolia starts at 0
params[:page] = (params.delete('page') || params.delete(:page)).to_i
params[:page] -= 1 if params[:page].to_i > 0
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_attributes
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_attributes(object)
# If a serializer is set, we ignore attributes
# everything should be done via the serializer
if not @serializer.nil?
attributes = @serializer.new(object).attributes
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_search
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def algolia_search(q, params = {})
if AlgoliaSearch.configuration[:pagination_backend]
# kaminari, will_paginate, and pagy start pagination at 1, Algolia starts at 0
params[:page] = (params.delete('page') || params.delete(:page)).to_i
params[:page] -= 1 if params[:page].to_i > 0
Method get_attributes
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_attributes(object)
# If a serializer is set, we ignore attributes
# everything should be done via the serializer
if not @serializer.nil?
attributes = @serializer.new(object).attributes
Method algolia_clear_index!
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def algolia_clear_index!(synchronous = false)
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
index = algolia_ensure_init(options, settings)
next if options[:replica]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_index_objects
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def algolia_index_objects(objects, synchronous = false)
algolia_configurations.each do |options, settings|
next if algolia_indexing_disabled?(options)
index = algolia_ensure_init(options, settings)
next if options[:replica]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_attribute_changed?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def algolia_attribute_changed?(object, attr_name, default)
# if one of two method is implemented, we return its result
# true/false means whether it has changed or not
# +#{attr_name}_changed?+ always defined for automatic attributes but deprecated after Rails 5.2
# +will_save_change_to_#{attr_name}?+ should be use instead for Rails 5.2+, also defined for automatic attributes.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method tags
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def tags(*args, &block)
raise ArgumentError.new('Cannot specify additional attributes on a replica index') if @options[:replica]
add_attribute :_tags do |o|
v = block_given? ? o.instance_eval(&block) : args
v.is_a?(Array) ? v : [v]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_attribute
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_attribute(*names, &block)
raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
raise ArgumentError.new('Cannot specify additional attributes on a replica index') if @options[:replica]
@additional_attributes ||= {}
names.each do |name|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_full_const_get
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def algolia_full_const_get(name)
list = name.split('::')
list.shift if list.first.blank?
obj = Object.const_defined?(:RUBY_VERSION) && RUBY_VERSION.to_f < 1.9 ? Object : self
list.each do |x|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method attribute
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def attribute(*names, &block)
raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
raise ArgumentError.new('Cannot specify additional attributes on a replica index') if @options[:replica]
@attributes ||= {}
names.flatten.each do |name|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return true
Avoid too many return
statements within this method. Open
return false
Method log_or_throw
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.log_or_throw(method, raise_on_failure, &block)
begin
yield
rescue Algolia::AlgoliaError => e
raise e if raise_on_failure
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_set_settings
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def algolia_set_settings(synchronous = false)
algolia_configurations.each do |options, settings|
if options[:primary_settings] && options[:inherit]
primary = options[:primary_settings].to_settings
primary.delete :replicas
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method algolia_enqueue_remove_from_index!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def algolia_enqueue_remove_from_index!(synchronous)
if algoliasearch_options[:enqueue]
algoliasearch_options[:enqueue].call(self, true) unless self.class.send(:algolia_indexing_disabled?, algoliasearch_options)
else
algolia_remove_from_index!(synchronous || algolia_synchronous?)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method included
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.included(base)
base.instance_eval do
alias_method :index!, :algolia_index! unless method_defined? :index!
alias_method :remove_from_index!, :algolia_remove_from_index! unless method_defined? :remove_from_index!
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"