Class: Yoda::Parsing::SourceAnalyzer Deprecated

Inherits:
Object
  • Object
show all
Includes:
AstTraversable
Defined in:
lib/yoda/parsing/source_analyzer.rb

Overview

Deprecated.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstTraversable

#calc_nodes_to_current_location

Constructor Details

#initialize(ast, location) ⇒ SourceAnalyzer

Returns a new instance of SourceAnalyzer.

Parameters:

  • ast (::Parser::AST::Node)
  • location (Location)


18
19
20
21
# File 'lib/yoda/parsing/source_analyzer.rb', line 18

def initialize(ast, location)
  @ast = ast
  @location = location
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



14
15
16
# File 'lib/yoda/parsing/source_analyzer.rb', line 14

def ast
  @ast
end

#locationObject (readonly)

Returns the value of attribute location.



14
15
16
# File 'lib/yoda/parsing/source_analyzer.rb', line 14

def location
  @location
end

Class Method Details

.from_source(source, location) ⇒ SourceAnalyzer

Parameters:

Returns:



10
11
12
# File 'lib/yoda/parsing/source_analyzer.rb', line 10

def self.from_source(source, location)
  new(Parser.new.parse(source), location)
end

Instance Method Details

#current_methodNodeObjects::MethodDefition?

Returns:

  • (NodeObjects::MethodDefition, nil)


54
55
56
# File 'lib/yoda/parsing/source_analyzer.rb', line 54

def current_method
  @current_method ||= namespace.calc_current_location_method(location)
end

#current_method_node::Parser::AST::Node

Returns:

  • (::Parser::AST::Node)


34
35
36
# File 'lib/yoda/parsing/source_analyzer.rb', line 34

def current_method_node
  nodes_to_current_location_from_root.reverse.find { |node| [:def, :defs].include?(node.type) }
end

#current_namespaceNodeObjects::Namespace?

Returns:



49
50
51
# File 'lib/yoda/parsing/source_analyzer.rb', line 49

def current_namespace
  @current_namespace ||= namespace.calc_current_location_namespace(location)
end

#current_namespace_nodesArray<::Parser::AST::Node>

Returns:

  • (Array<::Parser::AST::Node>)


39
40
41
# File 'lib/yoda/parsing/source_analyzer.rb', line 39

def current_namespace_nodes
  nodes_to_current_location_from_root.find_all { |node| [:class, :module, :sclass].include?(node.type) }
end

#namespaceNamespace

Returns:

  • (Namespace)


44
45
46
# File 'lib/yoda/parsing/source_analyzer.rb', line 44

def namespace
  @namespace ||= NodeObjects::Namespace.new(self.ast)
end

#nodes_to_current_location_from_rootArray<::Parser::AST::Node>

Returns:

  • (Array<::Parser::AST::Node>)


24
25
26
# File 'lib/yoda/parsing/source_analyzer.rb', line 24

def nodes_to_current_location_from_root
  @nodes_to_current_location ||= calc_nodes_to_current_location(ast, location)
end

#on_method?true, false

Returns:

  • (true, false)


29
30
31
# File 'lib/yoda/parsing/source_analyzer.rb', line 29

def on_method?
  !!current_method_node
end