Sha256: b876c41d3e42e051de85dafbc7855c559702856437a34424ea87f7c5cdd0838a

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

require 'set'
require 'reek/code_context'

class Class
  def is_overriding_method?(sym)
    instance_methods(false).include?(sym) and superclass.instance_methods(true).include?(sym)
  end
end

module Reek
  class ClassContext < CodeContext

    def ClassContext.create(outer, exp)
      res = Name.resolve(exp[1], outer)
      ClassContext.new(res[0], res[1], exp[2])
    end

    def ClassContext.from_s(src)
      source = Source.from_s(src)
      CodeParser.new(Sniffer.new).process_class(source.generate_syntax_tree)
    end

    def initialize(outer, name, superclass = nil)
      super(outer, nil)
      @name = name
      @superclass = superclass
      @parsed_methods = []
      @instance_variables = Set.new
    end

    def myself
      @myself ||= @outer.find_module(@name)
    end

    def find_module(modname)
      return nil unless myself
      @myself.const_or_nil(modname.to_s)
    end

    def is_overriding_method?(name)
      return false unless myself
      @myself.is_overriding_method?(name.to_s)
    end
    
    def is_struct?
      @superclass == [:const, :Struct]
    end

    def num_methods
      @parsed_methods.length
    end

    def record_instance_variable(sym)
      @instance_variables << Name.new(sym)
    end

    def record_method(name)
      @parsed_methods << name.to_s
    end

    def outer_name
      "#{@outer.outer_name}#{@name}#"
    end

    def to_s
      "#{@outer.outer_name}#{@name}"
    end

    def variable_names
      @instance_variables
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.3 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.4 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.5 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.6 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.7 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.8 lib/reek/class_context.rb
kevinrutherford-reek-1.1.3.9 lib/reek/class_context.rb