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

Included in:
CodeNode::IR::Node
Defined in:
lib/code_node/ir/node/query_methods.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?



14
15
16
# File 'lib/code_node/ir/node/query_methods.rb', line 14

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?



31
32
33
# File 'lib/code_node/ir/node/query_methods.rb', line 31

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?



25
26
27
# File 'lib/code_node/ir/node/query_methods.rb', line 25

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.



37
38
39
40
# File 'lib/code_node/ir/node/query_methods.rb', line 37

def inherits_from?(path)
  # TODO: need process all nodes first, marking for deletion on the first pass, because the superclass gets deleting and then the inherits from relation breaks down
  self.path == path || !@edge[:inherits_from].empty? && @edge[:inherits_from].values.first.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.



48
49
50
# File 'lib/code_node/ir/node/query_methods.rb', line 48

def island?
  @edge.values.all? &:empty?
end

#module?Boolean

Returns does this node represent a module?.

Returns:

  • (Boolean)

    does this node represent a module?



9
10
11
# File 'lib/code_node/ir/node/query_methods.rb', line 9

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.



19
20
21
# File 'lib/code_node/ir/node/query_methods.rb', line 19

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.



43
44
45
# File 'lib/code_node/ir/node/query_methods.rb', line 43

def singleton?
  @singleton
end