Class: Reek::ClassContext

Inherits:
CodeContext show all
Defined in:
lib/reek/class_context.rb

Instance Attribute Summary collapse

Attributes inherited from CodeContext

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CodeContext

#matches?, #method_missing

Constructor Details

#initialize(outer, name, superclass = nil) ⇒ ClassContext

SMELL: inconsistent with other contexts (not linked to the sexp)



30
31
32
33
34
35
36
37
# File 'lib/reek/class_context.rb', line 30

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Reek::CodeContext

Instance Attribute Details

#conditionalsObject (readonly)

Returns the value of attribute conditionals.



27
28
29
# File 'lib/reek/class_context.rb', line 27

def conditionals
  @conditionals
end

#parsed_methodsObject (readonly)

Returns the value of attribute parsed_methods.



27
28
29
# File 'lib/reek/class_context.rb', line 27

def parsed_methods
  @parsed_methods
end

Class Method Details

.create(outer, exp) ⇒ Object



16
17
18
19
# File 'lib/reek/class_context.rb', line 16

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

.from_s(src) ⇒ Object



21
22
23
24
25
# File 'lib/reek/class_context.rb', line 21

def ClassContext.from_s(src)
  source = src.to_reek_source
  sniffer = Sniffer.new(source)
  CodeParser.new(sniffer).process_class(source.syntax_tree)
end

Instance Method Details

#find_module(modname) ⇒ Object



43
44
45
46
# File 'lib/reek/class_context.rb', line 43

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

#is_overriding_method?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/reek/class_context.rb', line 48

def is_overriding_method?(name)
  return false unless myself
  @myself.is_overriding_method?(name.to_s)
end

#is_struct?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/reek/class_context.rb', line 53

def is_struct?
  @superclass == [:const, :Struct]
end

#myselfObject



39
40
41
# File 'lib/reek/class_context.rb', line 39

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

#num_methodsObject



57
58
59
# File 'lib/reek/class_context.rb', line 57

def num_methods
  @parsed_methods.length
end

#outer_nameObject



69
70
71
# File 'lib/reek/class_context.rb', line 69

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

#parameterized_methods(min_clump_size) ⇒ Object



85
86
87
# File 'lib/reek/class_context.rb', line 85

def parameterized_methods(min_clump_size)
  parsed_methods.select {|meth| meth.parameters.length >= min_clump_size }
end

#record_conditional(exp) ⇒ Object



81
82
83
# File 'lib/reek/class_context.rb', line 81

def record_conditional(exp)
  @conditionals << exp
end

#record_instance_variable(sym) ⇒ Object



61
62
63
# File 'lib/reek/class_context.rb', line 61

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

#record_method(meth) ⇒ Object



65
66
67
# File 'lib/reek/class_context.rb', line 65

def record_method(meth)
  @parsed_methods << meth
end

#to_sObject



73
74
75
# File 'lib/reek/class_context.rb', line 73

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

#variable_namesObject



77
78
79
# File 'lib/reek/class_context.rb', line 77

def variable_names
  @instance_variables
end