Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::NestedIterators

A Nested Iterator occurs when a block contains another block.

NestedIterators reports failing methods only once.

Constants

DEFAULT_IGNORE_ITERATORS
DEFAULT_MAX_ALLOWED_NESTING
IGNORE_ITERATORS_KEY

The name of the config field that sets the names of any methods for which nesting should not be considered

MAX_ALLOWED_NESTING_KEY

The name of the config field that sets the maximum depth of nested iterators to be permitted within any single method.

NESTING_DEPTH_KEY

SMELL: should be a subclass of UnnecessaryComplexity

SMELL_CLASS
SMELL_SUBCLASS

Public Class Methods

default_config() click to toggle source
# File lib/reek/smells/nested_iterators.rb, line 31
def self.default_config
  super.adopt(
    MAX_ALLOWED_NESTING_KEY => DEFAULT_MAX_ALLOWED_NESTING,
    IGNORE_ITERATORS_KEY => DEFAULT_IGNORE_ITERATORS
  )
end
new(source, config = NestedIterators.default_config) click to toggle source
# File lib/reek/smells/nested_iterators.rb, line 38
def initialize(source, config = NestedIterators.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(ctx) click to toggle source

Checks whether the given block is inside another.

@return [Array<SmellWarning>]

# File lib/reek/smells/nested_iterators.rb, line 47
def examine_context(ctx)
  @ignore_iterators = value(IGNORE_ITERATORS_KEY, ctx, DEFAULT_IGNORE_ITERATORS)
  @max_allowed_nesting = value(MAX_ALLOWED_NESTING_KEY, ctx, DEFAULT_MAX_ALLOWED_NESTING)
  find_deepest_iterators(ctx).map do |iter|
    depth = iter[1]
    SmellWarning.new(SMELL_CLASS, ctx.full_name, [iter[0].line],
      "contains iterators nested #{depth} deep",
      @source, SMELL_SUBCLASS,
      {NESTING_DEPTH_KEY => depth})
  end
  # BUG: no longer reports nesting outside methods (eg. in Optparse)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.