Sha256: 2036e1c85c68ac93cbffae68dcbecd83ad7860a2aa86a01694f163b2044871ab

Contents?: true

Size: 1.51 KB

Versions: 35

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require_relative 'code_context'
require_relative 'singleton_method_context'

module Reek
  module Context
    # Semi-transparent context to represent a metaclass while building the
    # context tree. This context will not be part of the resulting tree, but
    # will track context and visibility separately while building is in
    # progress.
    class GhostContext < ModuleContext
      attr_reader :children

      def register_with_parent(parent)
        @parent = parent
      end

      def append_child_context(child)
        real_parent = parent.append_child_context(child)
        super
        real_parent
      end

      # Return the correct class for child method contexts (representing nodes
      # of type `:def`). For GhostContext, this is the class that represents
      # singleton methods.
      def method_context_class
        SingletonMethodContext
      end

      # Return the correct class for child attribute contexts. For
      # GhostContext, this is the class that represents singleton attributes.
      def attribute_context_class
        SingletonAttributeContext
      end

      def track_visibility(visibility, names)
        visibility_tracker.track_visibility children: children,
                                            visibility: visibility,
                                            names: names
      end

      def record_use_of_self
        parent.record_use_of_self
      end

      def statement_counter
        parent.statement_counter
      end
    end
  end
end

Version data entries

35 entries across 33 versions & 2 rubygems

Version Path
reek-5.3.1 lib/reek/context/ghost_context.rb
reek-5.3.0 lib/reek/context/ghost_context.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/context/ghost_context.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/context/ghost_context.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/context/ghost_context.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/context/ghost_context.rb
reek-5.2.0 lib/reek/context/ghost_context.rb
reek-5.1.0 lib/reek/context/ghost_context.rb
reek-5.0.2 lib/reek/context/ghost_context.rb
reek-5.0.1 lib/reek/context/ghost_context.rb
reek-5.0.0 lib/reek/context/ghost_context.rb
reek-4.8.2 lib/reek/context/ghost_context.rb
reek-4.8.1 lib/reek/context/ghost_context.rb
reek-4.8.0 lib/reek/context/ghost_context.rb
reek-4.7.3 lib/reek/context/ghost_context.rb