Module: Hashira::Analysis::References
- Defined in:
- lib/hashira/analysis/references.rb
Class Method Summary collapse
- .branches(node) ⇒ Object
- .collect(node, accumulator) ⇒ Object
- .constant?(node) ⇒ Boolean
- .definition?(node) ⇒ Boolean
- .definition_branches(node) ⇒ Object
- .each_sighting(tree) ⇒ Object
- .list(tree) ⇒ Object
Class Method Details
.branches(node) ⇒ Object
27 28 29 |
# File 'lib/hashira/analysis/references.rb', line 27 def branches(node) definition?(node) ? definition_branches(node) : node.compact_child_nodes end |
.collect(node, accumulator) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/hashira/analysis/references.rb', line 18 def collect(node, accumulator) return unless node return accumulator << [Syntax.path_segments(node), node.location.start_line] if constant?(node) branches(node).each { collect(_1, accumulator) } end |
.constant?(node) ⇒ Boolean
25 |
# File 'lib/hashira/analysis/references.rb', line 25 def constant?(node) = node.is_a?(Prism::ConstantPathNode) || node.is_a?(Prism::ConstantReadNode) |
.definition?(node) ⇒ Boolean
31 |
# File 'lib/hashira/analysis/references.rb', line 31 def definition?(node) = node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode) |
.definition_branches(node) ⇒ Object
33 34 35 36 |
# File 'lib/hashira/analysis/references.rb', line 33 def definition_branches(node) superclass = node.is_a?(Prism::ClassNode) ? node.superclass : nil [superclass, node.body] end |
.each_sighting(tree) ⇒ Object
14 15 16 |
# File 'lib/hashira/analysis/references.rb', line 14 def each_sighting(tree) [].tap { collect(tree, _1) } end |
.list(tree) ⇒ Object
10 11 12 |
# File 'lib/hashira/analysis/references.rb', line 10 def list(tree) each_sighting(tree).map(&:first) end |