Class: Degem::Visitor

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/degem/parse_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVisitor

Returns a new instance of Visitor.



23
24
25
26
27
28
29
30
31
# File 'lib/degem/parse_ruby.rb', line 23

def initialize
  @requires = Set.new
  @paths = Set.new
  @classes = Set.new
  @modules = Set.new
  @path = nil
  @stack = []
  super
end

Instance Attribute Details

#path=(value) ⇒ Object (writeonly)

Sets the attribute path

Parameters:

  • value

    the value to set the attribute path to.



38
39
40
# File 'lib/degem/parse_ruby.rb', line 38

def path=(value)
  @path = value
end

Instance Method Details

#classesObject



36
# File 'lib/degem/parse_ruby.rb', line 36

def classes = @classes.to_a

#constsObject



34
# File 'lib/degem/parse_ruby.rb', line 34

def consts = (@paths.union(@classes).union(@modules)).to_a

#modulesObject



37
# File 'lib/degem/parse_ruby.rb', line 37

def modules = @modules.to_a

#pathsObject



35
# File 'lib/degem/parse_ruby.rb', line 35

def paths = @paths.to_a

#requiresObject



33
# File 'lib/degem/parse_ruby.rb', line 33

def requires = @requires.to_a

#visit_call_node(node) ⇒ Object



40
41
42
43
# File 'lib/degem/parse_ruby.rb', line 40

def visit_call_node(node)
  visit_require_call_node(node)
  super
end

#visit_class_node(node) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/degem/parse_ruby.rb', line 52

def visit_class_node(node)
  @stack.push(node)
  super
  @stack.pop
  *modules, klass = node.constant_path.full_name_parts rescue [[], node.name]
  @modules.add((@stack.map(&:name) + modules).join("::")) if modules.any?
  @classes.add((@stack.map(&:name) + modules + [klass]).join("::"))
end

#visit_constant_path_node(node) ⇒ Object



61
62
63
64
# File 'lib/degem/parse_ruby.rb', line 61

def visit_constant_path_node(node)
  paths_from(node).each { @paths.add(_1) }
  super
end

#visit_constant_read_node(node) ⇒ Object



66
67
68
69
# File 'lib/degem/parse_ruby.rb', line 66

def visit_constant_read_node(node)
  @paths.add(node.name.to_s) unless @stack.find { _1.constant_path == node }
  super
end

#visit_module_node(node) ⇒ Object



45
46
47
48
49
50
# File 'lib/degem/parse_ruby.rb', line 45

def visit_module_node(node)
  @stack.push(node)
  super
  @modules.add(@stack.map(&:name).join("::"))
  @stack.pop
end