File request.rb
has 512 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "cgi"
require "multi_json"
require 'crack'
require 'crack/xml'
Method do_request
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def do_request(etag)
http_headers = {}
http_headers["If-None-Match"] = etag if etag
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
headers.each do |key,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
Method call
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
def call(explicit_parameters=nil)
@instrumentation_name = "#{class_name}##{@method[:name]}"
result = nil
cached = nil
ActiveSupport::Notifications.instrument("request_call.active_rest_client", :name => @instrumentation_name) do
- 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 Request
has 31 methods (exceeds 20 allowed). Consider refactoring. Open
class Request
attr_accessor :post_params, :get_params, :url, :path, :headers, :method, :object, :body, :forced_url, :original_url
def initialize(method, object, params = {})
@method = method
Method handle_response
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def handle_response(response, cached = nil)
@response = response
status = @response.status || 200
if cached && response.status == 304
- 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 new_object
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def new_object(attributes, name = nil)
@method[:options][:has_many] ||= {}
name = name.to_sym rescue nil
if @method[:options][:has_many][name]
overridden_name = 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 generate_new_object
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def generate_new_object(options={})
if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
body = @response.body
elsif is_json_response?
body = @response.body.blank? ? {} : MultiJson.load(@response.body)
- 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 call
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
def call(explicit_parameters=nil)
@instrumentation_name = "#{class_name}##{@method[:name]}"
result = nil
cached = nil
ActiveSupport::Notifications.instrument("request_call.active_rest_client", :name => @instrumentation_name) do
Method do_request
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_request(etag)
http_headers = {}
http_headers["If-None-Match"] = etag if etag
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
headers.each do |key,value|
Method handle_hal_links_embedded
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def handle_hal_links_embedded(object, attributes)
attributes["_links"] = attributes[:_links] if attributes[:_links]
attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
if attributes["_links"]
attributes["_links"].each do |key, 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
Method handle_response
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_response(response, cached = nil)
@response = response
status = @response.status || 200
if cached && response.status == 304
Method new_object
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def new_object(attributes, name = nil)
@method[:options][:has_many] ||= {}
name = name.to_sym rescue nil
if @method[:options][:has_many][name]
overridden_name = name
Method hal_response?
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def hal_response?
_, content_type = @response.response_headers.detect{|k,v| k.downcase == "content-type"}
faked_response = @response.response_headers.detect{|k,v| k.downcase == "x-arc-faked-response"}
if content_type && content_type.respond_to?(:each)
content_type.each do |ct|
- 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 generate_new_object
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_new_object(options={})
if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
body = @response.body
elsif is_json_response?
body = @response.body.blank? ? {} : MultiJson.load(@response.body)
Method handle_hal_links_embedded
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_hal_links_embedded(object, attributes)
attributes["_links"] = attributes[:_links] if attributes[:_links]
attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
if attributes["_links"]
attributes["_links"].each do |key, value|
Consider simplifying this complex logical expression. Open
if @forced_url && @forced_url.present?
@url = @forced_url
else
@url = @method[:url].dup
matches = @url.scan(/(:[a-z_-]+)/)
Method prepare_url
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def prepare_url
if @forced_url && @forced_url.present?
@url = @forced_url
else
@url = @method[:url].dup
- 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 prepare_request_body
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def prepare_request_body(params = nil)
if request_body_type == :form_encoded
@body ||= (params || @post_params || {}).to_query
headers["Content-Type"] ||= "application/x-www-form-urlencoded"
elsif request_body_type == :json
- 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 prepare_params
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def prepare_params
params = @params || @object._attributes rescue {}
if params.is_a?(String) || params.is_a?(Fixnum)
params = {id:params}
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"