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
-
#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?.
14 15 16 |
# File 'lib/code_node/ir/node/query_methods.rb', line 14 def class? @node_type == :class end |
#extends?(path) ⇒ Boolean
31 32 33 |
# File 'lib/code_node/ir/node/query_methods.rb', line 31 def extends?(path) extends.member? path end |
#includes?(path) ⇒ Boolean
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
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.
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?.
9 10 11 |
# File 'lib/code_node/ir/node/query_methods.rb', line 9 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.
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.
43 44 45 |
# File 'lib/code_node/ir/node/query_methods.rb', line 43 def singleton? @singleton end |