Method set_record_value_for_attribute
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def set_record_value_for_attribute(record, attr, value)
value = value.to_time_in_current_zone if value.is_a?(Date) # convert Date to Time
unless attr[:read_only]
if attr[:setter]
attr[:setter].call(record, value)
- 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
Class ActiveRecordAdapter
has 36 methods (exceeds 20 allowed). Consider refactoring. Open
class ActiveRecordAdapter < AbstractAdapter
def self.for_class?(model)
model && model <= ActiveRecord::Base
end
File active_record_adapter.rb
has 347 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Netzke::Basepack::DataAdapters
# Implementation of {Netzke::Basepack::DataAdapters::AbstractAdapter}
class ActiveRecordAdapter < AbstractAdapter
def self.for_class?(model)
model && model <= ActiveRecord::Base
Method record_value_for_attribute
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def record_value_for_attribute(r, a, through_association = false)
v = if association_attr?(a)
split = a[:name].to_s.split(/\.|__/)
assoc = @model.reflect_on_association(split.first.to_sym)
if through_association
- 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_relation
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def get_relation(params = {})
relation = @model.all
query = params[:query]
- 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 combo_data
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def combo_data(attr, query = "")
method, assoc = method_and_assoc(attr[:name])
if assoc
# Options for an asssociation attribute
- 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 set_record_value_for_attribute
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_record_value_for_attribute(record, attr, value)
value = value.to_time_in_current_zone if value.is_a?(Date) # convert Date to Time
unless attr[:read_only]
if attr[:setter]
attr[:setter].call(record, value)
Method get_relation
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_relation(params = {})
relation = @model.all
query = params[:query]
Method record_value_for_attribute
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def record_value_for_attribute(r, a, through_association = false)
v = if association_attr?(a)
split = a[:name].to_s.split(/\.|__/)
assoc = @model.reflect_on_association(split.first.to_sym)
if through_association
Avoid deeply nested control flow statements. Open
if assoc.macro == :has_one
assoc_instance = record.send(assoc.name)
if assoc_instance
assoc_instance.send("#{assoc_method}=", value)
assoc_instance.save # what should we do when this fails?..
Method predicates_for_and_conditions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def predicates_for_and_conditions(conditions)
return nil if conditions.empty?
predicates = conditions.map do |q|
q = HashWithIndifferentAccess.new(Netzke::Support.permit_hash_params(q))
- 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"