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
-
#class? ⇒ Boolean
Does this node represent a class?.
- #extends?(path) ⇒ Boolean
- #includes?(path) ⇒ Boolean
- #inherits_from?(path) ⇒ Boolean
-
#island? ⇒ Boolean
Whether or not this node is an island.
-
#module? ⇒ Boolean
Does this node represent a module?.
-
#path ⇒ String
Fully qualified name of the node in the form
'Foo::Bar::Car'
. -
#singleton? ⇒ Boolean
Whether or not this node represents a singleton module.
Instance Method Details
#class? ⇒ Boolean
Returns 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
101 102 103 |
# File 'lib/code_node/ir/node.rb', line 101 def extends?(path) @extends.member? path end |
#includes?(path) ⇒ Boolean
95 96 97 |
# File 'lib/code_node/ir/node.rb', line 95 def includes?(path) @includes.member? path end |
#inherits_from?(path) ⇒ Boolean
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.
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?.
79 80 81 |
# File 'lib/code_node/ir/node.rb', line 79 def module? @node_type == :module end |
#path ⇒ String
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.
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.
112 113 114 |
# File 'lib/code_node/ir/node.rb', line 112 def singleton? @singleton end |