netzke/netzke-basepack

Very high overall complexity: 653

module Netzke::Basepack::DataAdapters
  # Implementation of {Netzke::Basepack::DataAdapters::AbstractAdapter}
  class ActiveRecordAdapter < AbstractAdapter
    def self.for_class?(model)
      model && model <= ActiveRecord::Base

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Complex class definition

module Netzke
  module Grid
    module Endpoints
      extend ActiveSupport::Concern

Found in Netzke::Grid::Endpoints - About 2 days to fix

    Very complex method in #set_record_value_for_attribute

        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)

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    High overall complexity: 223

    module Netzke
      module Basepack
        # Takes care of grid column configuration, as well as the grid's default form fields
        # +Grid::Base+ extends common Ext JS column options with the following ones:
        #
    Found in Netzke::Basepack::Columns - About 1 day to fix

    When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

    Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

    Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

    Refactorings

    Further Reading

    Very complex method in #combo_data

        def combo_data(attr, query = "")
          method, assoc = method_and_assoc(attr[:name])
    
          if assoc
            # Options for an asssociation attribute

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Very complex method in #record_value_for_attribute

        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

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Complex class definition

    module Netzke
      module Basepack
        # Search query builder used in Grid's advanced search.
        # Based on Ext.tab.Panel. A new tab is created for each OR condition. Each tab contains an instance of SearchPanel which is used to build AND conditions.
        class QueryBuilder < Netzke::Base
    Found in Netzke::Basepack::QueryBuilder - About 7 hrs to fix

      Complex class definition

      module Netzke
        module Grid
          # Child components for Grid and Tree
          module Components
            extend ActiveSupport::Concern
      Found in Netzke::Grid::Components - About 7 hrs to fix

        Complex method in #get_relation

            def get_relation(params = {})
              relation = @model.all
        
              query = params[:query]
        
        

        Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

        Refactorings

        Read More

        Complex class definition

        module Netzke
          module Tree
            module Endpoints
              extend ActiveSupport::Concern
        
        
        Found in Netzke::Tree::Endpoints - About 5 hrs to fix

          Complex method in #model_attributes

              def model_attributes
                @model_attributes ||= attribute_names.map do |column_name|
                  # If it's named as foreign key of some association, then it's an association column
                  assoc = @model.reflect_on_all_associations.detect { |a| a.foreign_key == column_name }
          
          

          Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

          Refactorings

          Read More

          Complex method in #predicates_for_and_conditions

              def predicates_for_and_conditions(conditions)
                return nil if conditions.empty?
          
                predicates = conditions.map do |q|
                  q = HashWithIndifferentAccess.new(q)

          Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

          Refactorings

          Read More

          Complex class definition

          module Netzke
            module Grid
              module Actions
                extend ActiveSupport::Concern
          
          
          Found in Netzke::Grid::Actions - About 4 hrs to fix

            Complex class definition

            module Netzke
              module Basepack
                # == Configuration
                # +load_last_preset+ - on load, tries to load the latest saved preset
                class SearchPanel < Base
            Found in Netzke::Basepack::SearchPanel - About 4 hrs to fix

              Complex method in #set_defaults

                    def set_defaults
                      super
              
                      self.type ||= @model_adapter.attr_type(name)
              
              
              Found in Netzke::Basepack::ColumnConfig - About 3 hrs to fix

              Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

              Refactorings

              Read More

              Complex class definition

              module Netzke
                module Form
                  module Endpoints
                    extend ActiveSupport::Concern
              
              
              Found in Netzke::Form::Endpoints - About 3 hrs to fix

                Complex class definition

                module Netzke
                  module Tree
                    # Ext.tree.Panel-based component with the following features:
                    #
                    # * CRUD operations
                Found in Netzke::Tree::Base - About 3 hrs to fix

                  Similar code found in 1 other location

                  module Netzke
                    module Grid
                      module Endpoints
                        extend ActiveSupport::Concern
                  
                  
                  Found in Netzke::Grid::Endpoints and 1 other location - About 3 hrs to fix
                  lib/netzke/grid/endpoints.rb on lines 68..73

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Refactorings

                  Further Reading

                  Similar code found in 1 other location

                  module Netzke
                    module Grid
                      module Endpoints
                        extend ActiveSupport::Concern
                  
                  
                  Found in Netzke::Grid::Endpoints and 1 other location - About 3 hrs to fix
                  lib/netzke/grid/endpoints.rb on lines 76..81

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Refactorings

                  Further Reading

                  Complex method in #create_or_update_record

                        def create_or_update_record(hsh)
                          hsh.merge!(config[:strong_values]) if config[:strong_values]
                  
                          # only pick the record specified in the params if it was not provided in the configuration
                          @record ||= model_adapter.find_record hsh.delete(model.primary_key.to_s)
                  Found in Netzke::Form::Services - About 3 hrs to fix

                  Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                  Refactorings

                  Read More

                  Similar code found in 1 other location

                  module Netzke
                    module Basepack
                      # == Configuration
                      # +load_last_preset+ - on load, tries to load the latest saved preset
                      class SearchPanel < Base
                  Found in Netzke::Basepack::SearchPanel and 1 other location - About 3 hrs to fix
                  lib/netzke/basepack/search_panel.rb on lines 13..16

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Refactorings

                  Further Reading

                  Similar code found in 1 other location

                  module Netzke
                    module Basepack
                      # == Configuration
                      # +load_last_preset+ - on load, tries to load the latest saved preset
                      class SearchPanel < Base
                  Found in Netzke::Basepack::SearchPanel and 1 other location - About 3 hrs to fix
                  lib/netzke/basepack/search_panel.rb on lines 25..28

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Refactorings

                  Further Reading

                  Complex class definition

                  module Netzke
                    module Grid
                      # Ext.grid.Panel-based component with the following features:
                      #
                      # * infinite scrolling or pagination
                  Found in Netzke::Grid::Base - About 3 hrs to fix

                    Complex method in #apply_column_sorting

                        def apply_column_sorting(relation, column, dir)
                          assoc, method = column[:name].split('__')
                    
                          # if a sorting scope is set, call the scope with the given direction
                          if column[:sorting_scope].is_a?(Proc)

                    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                    Refactorings

                    Read More

                    Complex class definition

                    module Netzke
                      module Basepack
                        # When mixed into a component with resizable layout (e.g. border layout), this module enables persistence for regions size and collapsed/expanded state.
                        module ItemPersistence
                          extend ActiveSupport::Concern
                    Found in Netzke::Basepack::ItemPersistence - About 2 hrs to fix

                      Complex method in #build_form_errors

                            def build_form_errors(record)
                              form_errors = {}
                              foreign_keys = model_adapter.hash_fk_model
                              record.errors.to_hash.map{|field, error|
                                # some ORM return an array for error
                      Found in Netzke::Form::Services - About 2 hrs to fix

                      Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                      Refactorings

                      Read More

                      Complex method in #insert_primary_column

                            def insert_primary_column(cols)
                              primary_key = model_adapter.primary_key
                              raise "Model #{model_adapter.model.name} does not have a primary column" if primary_key.blank?
                              c = Netzke::Basepack::ColumnConfig.new(model_adapter.primary_key, model_adapter)
                              c.merge_attribute(attribute_overrides[c.name.to_sym]) if attribute_overrides.has_key?(c.name.to_sym)
                      Found in Netzke::Basepack::Columns - About 2 hrs to fix

                      Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                      Refactorings

                      Read More

                      Complex method in #extend_field

                            def extend_field(field)
                              Netzke::Basepack::FieldConfig.new(field, model_adapter).tap do |c|
                                # not binding to a model attribute
                                return c if c.bind == false
                      
                      
                      Found in Netzke::Basepack::Fields - About 2 hrs to fix

                      Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                      Refactorings

                      Read More

                      Complex method in #get_association_values

                            def get_association_values
                              fields_that_need_associated_values = fields.select{ |k,v| k.to_s.index("__") && !fields[k][:nested_attribute] }
                              # Take care of Ruby 1.8.7
                              if fields_that_need_associated_values.is_a?(Array)
                                fields_that_need_associated_values = fields_that_need_associated_values.inject({}){|r,(k,v)| r.merge(k => v)}
                      Found in Netzke::Form::Base - About 1 hr to fix

                      Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

                      Refactorings

                      Read More