Class: CodeNode::SexpWalker
- Inherits:
-
Object
- Object
- CodeNode::SexpWalker
- Defined in:
- lib/code_node/sexp_walker.rb
Overview
Walks a Sexp representing a ruby file looking for classes and modules.
Instance Method Summary collapse
-
#initialize(graph, sexp, opt = {}) ⇒ SexpWalker
constructor
Initialize a walker with a graph and sexp.
-
#walk(s = nil) ⇒ nil
Walk the tree rooted at the given sexp.
Constructor Details
#initialize(graph, sexp, opt = {}) ⇒ SexpWalker
Initialize a walker with a graph and sexp
All files in a code base should be walked once in :find_nodes
mode, and then walked again in :find_relations
mode.
14 15 16 17 18 |
# File 'lib/code_node/sexp_walker.rb', line 14 def initialize(graph, sexp, opt={}) @graph = graph @root = sexp @mode = opt[:mode] || :find_nodes end |
Instance Method Details
#walk(s = nil) ⇒ nil
Walk the tree rooted at the given sexp
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/code_node/sexp_walker.rb', line 23 def walk(s = nil) s ||= @root if [:module, :class].member?(s[0]) add_node s elsif find_relations? && s[0] == :call && s.length >= 4 && [:extend, :include].member?(s[2]) && !@graph.scope.empty? add_relation s else walk_siblings s.slice(1..-1) end end |