Sha256: cb261b39cced2a372ec1a2caff8a0aef5c378f450e44f533c9523685af9e5543

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

module Reek
  module Core

    #
    # Superclass for all types of source code context. Each instance represents
    # a code element of some kind, and each provides behaviour relevant to that
    # code element. CodeContexts form a tree in the same way the code does,
    # with each context holding a reference to a unique outer context.
    #
    class CodeContext

      attr_reader :exp, :config

      def initialize(outer, exp)
        @outer = outer
        @exp = exp
        @config = local_config
      end

      def name
        @exp.name
      end

      def local_nodes(type, &blk)
        each_node(type, [:class, :module], &blk)
      end

      def each_node(type, ignoring, &blk)
        @exp.each_node(type, ignoring, &blk)
      end

      def matches?(candidates)
        my_fq_name = full_name
        candidates.any? {|str| /#{str}/ === my_fq_name }
      end

      #
      # Bounces messages up the context tree to the first enclosing context
      # that knows how to deal with the request.
      #
      def method_missing(method, *args)
        @outer.send(method, *args)
      end

      def num_methods
        0
      end

      def full_name
        outer = @outer ? @outer.full_name : ''
        exp.full_name(outer)
      end

      def local_config
        return Hash.new if @exp.nil?
        config = Source::CodeComment.new(@exp.comments || '').config
        return config unless @outer
        @outer.config.deep_copy.adopt!(config)
        # no tests for this -----^
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
reek-1.3.5 lib/reek/core/code_context.rb
reek-1.3.4 lib/reek/core/code_context.rb
reek-1.3.3 lib/reek/core/code_context.rb
reek-1.3.2 lib/reek/core/code_context.rb
reek-1.3.1 lib/reek/core/code_context.rb
reek-1.3 lib/reek/core/code_context.rb
reek-1.2.13 lib/reek/core/code_context.rb
reek-1.2.12 lib/reek/core/code_context.rb
reek-1.2.11 lib/reek/core/code_context.rb
reek-1.2.10 lib/reek/core/code_context.rb
reek-1.2.9 lib/reek/core/code_context.rb
reek-1.2.8 lib/reek/core/code_context.rb