esbanarango/acts_as_inheritable

View on GitHub
lib/acts_as_inheritable.rb

Summary

Maintainability
C
1 day
Test Coverage

Assignment Branch Condition size for acts_as_inheritable is too high. [103/15]
Open

  def acts_as_inheritable(options)
    fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?

    class_attribute :inheritable_configuration
Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [72/10]
Open

  def acts_as_inheritable(options)
    fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?

    class_attribute :inheritable_configuration
Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for verify_parent_name is too high. [37.01/15]
Open

      def verify_parent_name(new_relation, model_parent)
        parent_name = model_parent.class.to_s.downcase
        return parent_name if new_relation.respond_to?(parent_name)
        many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
        many_and_one_associations.each do |association|
Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for acts_as_inheritable is too high. [27/7]
Open

  def acts_as_inheritable(options)
    fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?

    class_attribute :inheritable_configuration
Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for acts_as_inheritable is too high. [25/6]
Open

  def acts_as_inheritable(options)
    fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?

    class_attribute :inheritable_configuration
Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Block has too many lines. [65/25]
Open

    class_eval do
      def has_parent?
        parent.present?
      end

Severity: Minor
Found in lib/acts_as_inheritable.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Method verify_parent_name has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

      def verify_parent_name(new_relation, model_parent)
        parent_name = model_parent.class.to_s.downcase
        return parent_name if new_relation.respond_to?(parent_name)
        many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
        many_and_one_associations.each do |association|
Severity: Minor
Found in lib/acts_as_inheritable.rb - About 3 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 acts_as_inheritable has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def acts_as_inheritable(options)
    fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?

    class_attribute :inheritable_configuration
Severity: Major
Found in lib/acts_as_inheritable.rb - About 2 hrs to fix

    Method has too many lines. [19/10]
    Open

          def verify_parent_name(new_relation, model_parent)
            parent_name = model_parent.class.to_s.downcase
            return parent_name if new_relation.respond_to?(parent_name)
            many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
            many_and_one_associations.each do |association|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for inherit_attributes is too high. [20.35/15]
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
            available_methods = ['update_attributes', 'update_columns']
            if has_parent? && self.class.inheritable_configuration[:attributes]
              # Attributes
              self.class.inheritable_configuration[:attributes].each do |attribute|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method has too many lines. [13/10]
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
            available_methods = ['update_attributes', 'update_columns']
            if has_parent? && self.class.inheritable_configuration[:attributes]
              # Attributes
              self.class.inheritable_configuration[:attributes].each do |attribute|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [13/10]
    Open

          def inherit_instance(current, model_parent, relation, relation_instance)
            new_relation = relation_instance.dup
            belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
            saved =
              # Is a `belongs_to` association
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method inherit_attributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
            available_methods = ['update_attributes', 'update_columns']
            if has_parent? && self.class.inheritable_configuration[:attributes]
              # Attributes
              self.class.inheritable_configuration[:attributes].each do |attribute|
    Severity: Minor
    Found in lib/acts_as_inheritable.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

    Perceived complexity for inherit_attributes is too high. [9/7]
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
            available_methods = ['update_attributes', 'update_columns']
            if has_parent? && self.class.inheritable_configuration[:attributes]
              # Attributes
              self.class.inheritable_configuration[:attributes].each do |attribute|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Cyclomatic complexity for verify_parent_name is too high. [8/6]
    Open

          def verify_parent_name(new_relation, model_parent)
            parent_name = model_parent.class.to_s.downcase
            return parent_name if new_relation.respond_to?(parent_name)
            many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
            many_and_one_associations.each do |association|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Cyclomatic complexity for inherit_attributes is too high. [8/6]
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
            available_methods = ['update_attributes', 'update_columns']
            if has_parent? && self.class.inheritable_configuration[:attributes]
              # Attributes
              self.class.inheritable_configuration[:attributes].each do |attribute|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Perceived complexity for verify_parent_name is too high. [8/7]
    Open

          def verify_parent_name(new_relation, model_parent)
            parent_name = model_parent.class.to_s.downcase
            return parent_name if new_relation.respond_to?(parent_name)
            many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
            many_and_one_associations.each do |association|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Assignment Branch Condition size for inherit_instance is too high. [15.17/15]
    Open

          def inherit_instance(current, model_parent, relation, relation_instance)
            new_relation = relation_instance.dup
            belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
            saved =
              # Is a `belongs_to` association
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method inherit_instance has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def inherit_instance(current, model_parent, relation, relation_instance)
            new_relation = relation_instance.dup
            belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
            saved =
              # Is a `belongs_to` association
    Severity: Minor
    Found in lib/acts_as_inheritable.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 inherit_relations has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def inherit_relations(model_parent = send(:parent), current = self)
            if model_parent && current.class.method_defined?(:inheritable_configuration) && current.class.inheritable_configuration[:associations]
              current.class.inheritable_configuration[:associations].each do |relation|
                parent_relation = model_parent.send(relation)
                relation_instances = parent_relation.respond_to?(:each) ? parent_relation : [parent_relation].compact
    Severity: Minor
    Found in lib/acts_as_inheritable.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

    Use casecmp instead of downcase ==.
    Open

              next unless association.klass.to_s.downcase == new_relation.class.to_s.downcase && association.options.key?(:as)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop identifies places where a case-insensitive string comparison can better be implemented using casecmp.

    Example:

    # bad
    str.downcase == 'abc'
    str.upcase.eql? 'ABC'
    'abc' == str.downcase
    'ABC'.eql? str.upcase
    str.downcase == str.downcase
    
    # good
    str.casecmp('ABC').zero?
    'abc'.casecmp(str).zero?

    Line is too long. [82/80]
    Open

                  inherit_instance(current, model_parent, relation, relation_instance)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [83/80]
    Open

              if new_relation.respond_to?(as) && !new_relation.respond_to?(parent_name)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

            if has_parent? && self.class.inheritable_configuration[:attributes]
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Space inside { missing.
    Open

                    send(method_to_update, {attribute => parent.send(attribute)})
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Line is too long. [93/80]
    Open

        fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [104/80]
    Open

                next unless new_relation.class.reflections[reflection].class_name == model_parent.class.name
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [142/80]
    Open

            if model_parent && current.class.method_defined?(:inheritable_configuration) && current.class.inheritable_configuration[:associations]
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [120/80]
    Open

            many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [83/80]
    Open

              current.class.inheritable_configuration[:associations].each do |relation|
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Rename has_parent? to parent?.
    Open

          def has_parent?
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

    Line is too long. [113/80]
    Open

                relation_instances = parent_relation.respond_to?(:each) ? parent_relation : [parent_relation].compact
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [115/80]
    Open

            belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [103/80]
    Open

        fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Always use raise to signal exceptions.
    Open

        fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks for uses of fail and raise.

    Example: EnforcedStyle: only_raise (default)

    # The `only_raise` style enforces the sole use of `raise`.
    # bad
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail
    
    # good
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise

    Example: EnforcedStyle: only_fail

    # The `only_fail` style enforces the sole use of `fail`.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail

    Example: EnforcedStyle: semantic

    # The `semantic` style enforces the use of `fail` to signal an
    # exception, then will use `raise` to trigger an offense after
    # it has been rescued.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      # Error thrown
    rescue Exception
      fail
    end
    
    Kernel.fail
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      raise 'Preferably with descriptive message'
    end
    
    explicit_receiver.fail
    explicit_receiver.raise

    Line is too long. [82/80]
    Open

                if (force && !not_force_for.include?(attribute)) || current_val.blank?
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Use %w or %W for an array of words.
    Open

            available_methods = ['update_attributes', 'update_columns']
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.

    Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %w[foo bar baz]
    
    # bad
    ['foo', 'bar', 'baz']

    Example: EnforcedStyle: brackets

    # good
    ['foo', 'bar', 'baz']
    
    # bad
    %w[foo bar baz]

    Space inside } missing.
    Open

                    send(method_to_update, {attribute => parent.send(attribute)})
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Line is too long. [122/80]
    Open

              next unless association.klass.to_s.downcase == new_relation.class.to_s.downcase && association.options.key?(:as)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [87/80]
    Open

          def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Line is too long. [81/80]
    Open

                  if method_to_update && available_methods.include?(method_to_update)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Redundant curly braces around a hash parameter.
    Open

                    send(method_to_update, {attribute => parent.send(attribute)})
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

    Example: EnforcedStyle: braces

    # The `braces` style enforces braces around all method
    # parameters that are hashes.
    
    # bad
    some_method(x, y, a: 1, b: 2)
    
    # good
    some_method(x, y, {a: 1, b: 2})

    Example: EnforcedStyle: no_braces (default)

    # The `no_braces` style checks that the last parameter doesn't
    # have braces around it.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    
    # good
    some_method(x, y, a: 1, b: 2)

    Example: EnforcedStyle: context_dependent

    # The `context_dependent` style checks that the last parameter
    # doesn't have braces around it, but requires braces if the
    # second to last parameter is also a hash literal.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
    
    # good
    some_method(x, y, a: 1, b: 2)
    some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

            if model_parent && current.class.method_defined?(:inheritable_configuration) && current.class.inheritable_configuration[:associations]
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Line is too long. [101/80]
    Open

                new_relation = relation_instance.duplicate! if relation_instance.respond_to?(:duplicate!)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    Always use raise to signal exceptions.
    Open

        fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks for uses of fail and raise.

    Example: EnforcedStyle: only_raise (default)

    # The `only_raise` style enforces the sole use of `raise`.
    # bad
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail
    
    # good
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise

    Example: EnforcedStyle: only_fail

    # The `only_fail` style enforces the sole use of `fail`.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail

    Example: EnforcedStyle: semantic

    # The `semantic` style enforces the use of `fail` to signal an
    # exception, then will use `raise` to trigger an offense after
    # it has been rescued.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      # Error thrown
    rescue Exception
      fail
    end
    
    Kernel.fail
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      raise 'Preferably with descriptive message'
    end
    
    explicit_receiver.fail
    explicit_receiver.raise

    Redundant self detected.
    Open

        self.inheritable_configuration.merge!(options)
    Severity: Minor
    Found in lib/acts_as_inheritable.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    There are no issues that match your filters.

    Category
    Status