Class: RubyDetective::AST::Nodes::GenericNode

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_detective/ast/nodes/generic_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast_node, file_path:, parent_node:) ⇒ GenericNode

Returns a new instance of GenericNode.



7
8
9
10
11
12
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 7

def initialize(ast_node, file_path:, parent_node:)
  @ast_node = ast_node
  @file_path = file_path
  @children = []
  @parent_node = parent_node
end

Instance Attribute Details

#ast_nodeObject (readonly)

Returns the value of attribute ast_node.



5
6
7
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 5

def ast_node
  @ast_node
end

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 5

def children
  @children
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 5

def file_path
  @file_path
end

#parent_nodeObject (readonly)

Returns the value of attribute parent_node.



5
6
7
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 5

def parent_node
  @parent_node
end

Instance Method Details

#absolute_path_sign_node?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 38

def absolute_path_sign_node?
  type == :absolute_path_sign
end

#class_declaration_node?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 26

def class_declaration_node?
  type == :class
end

#constant_reference_node?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 34

def constant_reference_node?
  type == :constant
end

#declared_namespaceObject



22
23
24
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 22

def declared_namespace
  []
end

#first_lineObject



54
55
56
57
58
59
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 54

def first_line
  # When the node represents something that is not directly in the code
  # the `ast_node.loc.expression` can be nil, and since `.line` is just
  # sugar syntax for `loc.expression.line` it would throw an error.
  ast_node.loc.line rescue nil
end

#generic_node?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 46

def generic_node?
  type == :generic
end

#last_lineObject



61
62
63
64
65
66
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 61

def last_line
  # When the node represents something that is not directly in the code
  # the `ast_node.loc.expression` can be nil, and since `.last_line` is just
  # sugar syntax for `loc.expression.last_line` it would throw an error.
  ast_node.loc.last_line rescue nil
end

#module_declaration_node?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 30

def module_declaration_node?
  type == :module
end

#namespaceObject



18
19
20
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 18

def namespace
  build_namespace(self)
end

#queryObject



68
69
70
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 68

def query
  Query.new(self)
end

#raw_childrenObject



72
73
74
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 72

def raw_children
  ast_node.children
end

#short_namespaceObject



14
15
16
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 14

def short_namespace
  namespace[0..-2]
end

#typeObject



50
51
52
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 50

def type
  :generic
end

#value_node?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ruby_detective/ast/nodes/generic_node.rb', line 42

def value_node?
  type == :value
end