Class: Pelusa::ClassAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/pelusa/class_analyzer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ClassAnalyzer

Public: Initializes a ClassAnalyzer.

klass - The class AST node.



5
6
7
# File 'lib/pelusa/class_analyzer.rb', line 5

def initialize(klass)
  @klass = klass
end

Class Method Details

.walk(start_node) ⇒ Object

Public: Walk a node, analyzing it as it goes.

block - supply a block that will be executed as the node gets walked.

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
# File 'lib/pelusa/class_analyzer.rb', line 37

def self.walk(start_node)
  raise ArgumentError, "Walk requires a block!" unless block_given?
  start_node.walk do |continue, node|
    yield(node)
    true
  end
end

Instance Method Details

#analyze(lints) ⇒ Object

Public: Analyzes a class with a series of lints.

lints - The lints to check for.

Returns a collection of Analysis, one for each lint.



27
28
29
30
31
32
# File 'lib/pelusa/class_analyzer.rb', line 27

def analyze(lints)
  lints.map do |lint_class|
    lint = lint_class.new
    lint.check(@klass)
  end
end

#class_nameObject

Public: Returns the name of the Class being analyzed.

Returns the String name.



12
13
14
15
# File 'lib/pelusa/class_analyzer.rb', line 12

def class_name
  name = @klass.name
  name.name
end

#typeObject

Public: Returns the type of container being examined (class or module).



18
19
20
# File 'lib/pelusa/class_analyzer.rb', line 18

def type
  @klass.is_a?(Rubinius::ToolSets::Runtime::ToolSet::AST::Class) ? "class" : "module"
end