Class: Phlexing::RubyAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/phlexing/ruby_analyzer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRubyAnalyzer

Returns a new instance of RubyAnalyzer.



13
14
15
16
17
18
19
20
21
22
# File 'lib/phlexing/ruby_analyzer.rb', line 13

def initialize
  @ivars = Set.new
  @locals = Set.new
  @idents = Set.new
  @calls = Set.new
  @consts = Set.new
  @instance_methods = Set.new
  @includes = Set.new
  @visitor = Visitor.new(self)
end

Instance Attribute Details

#callsObject

Returns the value of attribute calls.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def calls
  @calls
end

#constsObject

Returns the value of attribute consts.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def consts
  @consts
end

#identsObject

Returns the value of attribute idents.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def idents
  @idents
end

#includesObject

Returns the value of attribute includes.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def includes
  @includes
end

#instance_methodsObject

Returns the value of attribute instance_methods.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def instance_methods
  @instance_methods
end

#ivarsObject

Returns the value of attribute ivars.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def ivars
  @ivars
end

#localsObject

Returns the value of attribute locals.



7
8
9
# File 'lib/phlexing/ruby_analyzer.rb', line 7

def locals
  @locals
end

Class Method Details

.call(source) ⇒ Object



9
10
11
# File 'lib/phlexing/ruby_analyzer.rb', line 9

def self.call(source)
  new.analyze(source)
end

Instance Method Details

#analyze(source) ⇒ Object



24
25
26
27
28
# File 'lib/phlexing/ruby_analyzer.rb', line 24

def analyze(source)
  code = extract_ruby_from_erb(source.to_s)

  analyze_ruby(code)
end

#analyze_ruby(code) ⇒ Object



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

def analyze_ruby(code)
  program = SyntaxTree.parse(code)
  @visitor.visit(program)

  self
rescue SyntaxTree::Parser::ParseError, NoMethodError
  self
end