ruby-grape/grape-entity

View on GitHub

Showing 10 of 10 total issues

Class Entity has 42 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Entity
    attr_reader :object, :delegator, :options

    # The Entity DSL allows you to mix entity functionality into
    # your existing classes.
Severity: Minor
Found in lib/grape_entity/entity.rb - About 5 hrs to fix

    File entity.rb has 276 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'grape_entity/json'
    
    module Grape
      # An Entity is a lightweight structure that allows you to easily
      # represent data from your application in a consistent and abstracted
    Severity: Minor
    Found in lib/grape_entity/entity.rb - About 2 hrs to fix

      Method normalized_exposures has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

              def normalized_exposures(entity, options)
                return easy_normalized_exposures(entity, options) unless deep_complex_nesting?(entity) # optimization
      
                table = nested_exposures.each_with_object({}) do |exposure, output|
                  should_expose = exposure.with_attr_path(entity, options) do
      Severity: Minor
      Found in lib/grape_entity/exposure/nesting_exposure.rb - About 2 hrs to fix

      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 expose has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.expose(*args, &block)
            options = merge_options(args.last.is_a?(Hash) ? args.pop : {})
      
            if args.size > 1
      
      
      Severity: Minor
      Found in lib/grape_entity/entity.rb - About 2 hrs to fix

      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 merge_options has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.merge_options(options)
            opts = {}
      
            merge_logic = proc do |key, existing_val, new_val|
              if %i[if unless].include?(key)
      Severity: Minor
      Found in lib/grape_entity/entity.rb - About 1 hr to fix

      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 normalized_exposures has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def normalized_exposures(entity, options)
                return easy_normalized_exposures(entity, options) unless deep_complex_nesting?(entity) # optimization
      
                table = nested_exposures.each_with_object({}) do |exposure, output|
                  should_expose = exposure.with_attr_path(entity, options) do
      Severity: Minor
      Found in lib/grape_entity/exposure/nesting_exposure.rb - About 1 hr to fix

        Method represent has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.represent(objects, options = {})
              @present_collection ||= nil
              if objects.respond_to?(:to_ary) && !@present_collection
                root_element = root_element(:collection_root)
                inner = objects.to_ary.map { |object| new(object, options.reverse_merge(collection: true)).presented }
        Severity: Minor
        Found in lib/grape_entity/entity.rb - About 55 mins to fix

        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 expose_nil_condition has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

                def expose_nil_condition(attribute, options)
                  Condition.new_unless(
                    proc do |object, entity_options|
                      if options[:proc].nil?
                        delegator = Delegator.new(object)
        Severity: Minor
        Found in lib/grape_entity/exposure.rb - About 45 mins to fix

        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 exec_with_object has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def exec_with_object(options, &block)
              if block.parameters.count == 1
                instance_exec(object, &block)
              else
                instance_exec(object, options, &block)
        Severity: Minor
        Found in lib/grape_entity/entity.rb - About 35 mins to fix

        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 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                  def add(exposure, result)
                    # Save a result array in collections' array if it should be merged
                    if result.is_a?(Array) && exposure.for_merge
                      @output_collection << result
                    elsif exposure.for_merge
        Severity: Minor
        Found in lib/grape_entity/exposure/nesting_exposure/output_builder.rb - About 35 mins to fix

        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

        Severity
        Category
        Status
        Source
        Language