Sha256: b0b94bf1b71dd0c43be4f6131a6821002b183aff2a3de1aaae0786cbd3d5e929

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require_relative 'code_context'

module Reek
  module Context
    #
    # A context wrapper for any method definition found in a syntax tree.
    #
    # @api private
    class MethodContext < CodeContext
      attr_reader :refs

      def envious_receivers
        return {} if refs.self_is_max?
        refs.most_popular
      end

      def references_self?
        exp.depends_on_instance?
      end

      def uses_param?(param)
        local_nodes(:lvar).find { |node| node.var_name == param.to_sym }
      end

      def unused_params
        exp.arguments.select do |param|
          next if param.anonymous_splat?
          next if param.marked_unused?
          !uses_param? param.plain_name
        end
      end

      def uses_super_with_implicit_arguments?
        (body = exp.body) && body.contains_nested_node?(:zsuper)
      end

      def default_assignments
        @default_assignments ||=
          exp.parameters.select(&:optional_argument?).map(&:children)
      end

      def singleton_method?
        exp.singleton_method? || visibility == :module_function
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-3.3.1 lib/reek/context/method_context.rb
reek-3.3.0 lib/reek/context/method_context.rb
reek-3.2.1 lib/reek/context/method_context.rb
reek-3.2 lib/reek/context/method_context.rb
reek-3.1 lib/reek/context/method_context.rb