Module: CodeNode::IR::Node::QueryMethods

Included in:
CodeNode::IR::Node
Defined in:
lib/code_node/ir/node.rb

Overview

CodeNode::IR::Node methods which are useful for querying in matchers

Instance Method Summary collapse

Instance Method Details

#class?Boolean

Returns does this node represent a class?.

Returns:

  • (Boolean)

    does this node represent a class?



84
85
86
# File 'lib/code_node/ir/node.rb', line 84

def class?
  @node_type == :class
end

#extends?(path) ⇒ Boolean

Returns does this node extend a #module? node with the given #path?.

Parameters:

  • path (String)

    a class or module path in the form Foo::Bar::Car

Returns:

  • (Boolean)

    does this node extend a #module? node with the given #path?



101
102
103
# File 'lib/code_node/ir/node.rb', line 101

def extends?(path)
  @extends.member? path
end

#includes?(path) ⇒ Boolean

Returns does this node include a #module? node with the given #path?.

Parameters:

  • path (String)

    a class or module path in the form Foo::Bar::Car

Returns:

  • (Boolean)

    does this node include a #module? node with the given #path?



95
96
97
# File 'lib/code_node/ir/node.rb', line 95

def includes?(path)
  @includes.member? path
end

#inherits_from?(path) ⇒ Boolean

Returns does this node inherit from (directly or indirectly) a #class? node with the given #path? Note that a node inherits from itself according to this method. Recursively checks the ancestry of the node.

Parameters:

  • path (String)

    a class or module path in the form Foo::Bar::Car

Returns:

  • (Boolean)

    does this node inherit from (directly or indirectly) a #class? node with the given #path? Note that a node inherits from itself according to this method. Recursively checks the ancestry of the node.



107
108
109
# File 'lib/code_node/ir/node.rb', line 107

def inherits_from?(path)
  self.path == path || @inherits_from && (@inherits_from.path == path || @inherits_from.inherits_from?(path))
end

#island?Boolean

Returns whether or not this node is an island. An island is a node with no connections to other nodes.

Returns:

  • (Boolean)

    whether or not this node is an island. An island is a node with no connections to other nodes.



117
118
119
120
# File 'lib/code_node/ir/node.rb', line 117

def island?
  ([@parent, @inherits_from].all?(&:nil?) &&
   [@children, @inherited_by, @extends, @includes, @extended_by, @included_by].all?(&:empty?))
end

#module?Boolean

Returns does this node represent a module?.

Returns:

  • (Boolean)

    does this node represent a module?



79
80
81
# File 'lib/code_node/ir/node.rb', line 79

def module?
  @node_type == :module
end

#pathString

Returns fully qualified name of the node in the form 'Foo::Bar::Car'. Not good as a graphviz identifier because of the colon (:) characters. Use TemplateMethods#key for graphviz identifiers instead.

Returns:

  • (String)

    fully qualified name of the node in the form 'Foo::Bar::Car'. Not good as a graphviz identifier because of the colon (:) characters. Use TemplateMethods#key for graphviz identifiers instead.



89
90
91
# File 'lib/code_node/ir/node.rb', line 89

def path
  @path.join '::'
end

#singleton?Boolean

Returns whether or not this node represents a singleton module. A singleton module is one which contains an extend self statement.

Returns:

  • (Boolean)

    whether or not this node represents a singleton module. A singleton module is one which contains an extend self statement.



112
113
114
# File 'lib/code_node/ir/node.rb', line 112

def singleton?
  @singleton
end