Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::LongYieldList

A variant on LongParameterList that checks the number of items passed to a block by a yield call.

Constants

DEFAULT_MAX_ALLOWED_PARAMS

The default value of the MAX_ALLOWED_PARAMS_KEY configuration value.

MAX_ALLOWED_PARAMS_KEY

The name of the config field that sets the maximum number of parameters permitted in any method or block.

PARAMETER_COUNT_KEY
SMELL_CLASS
SMELL_SUBCLASS

Public Class Methods

default_config() click to toggle source
# File lib/reek/smells/long_yield_list.rb, line 26
def self.default_config
  super.adopt(
          MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS
  )
end
new(source, config = LongYieldList.default_config) click to toggle source
# File lib/reek/smells/long_yield_list.rb, line 32
def initialize(source, config = LongYieldList.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(method_ctx) click to toggle source

Checks the number of parameters in the given scope.

@return [Array<SmellWarning>]

# File lib/reek/smells/long_yield_list.rb, line 41
def examine_context(method_ctx)
  @max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, method_ctx, DEFAULT_MAX_ALLOWED_PARAMS)
  method_ctx.local_nodes(:yield).select do |yield_node|
    yield_node.args.length > @max_allowed_params
  end.map do |yield_node|
    num_params = yield_node.args.length
    SmellWarning.new(SMELL_CLASS, method_ctx.full_name, [yield_node.line],
                     "yields #{num_params} parameters",
                     @source, SMELL_SUBCLASS, {PARAMETER_COUNT_KEY => num_params})
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.