Class: CodeGraph::InheritanceProcessor
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- CodeGraph::InheritanceProcessor
- Defined in:
- lib/codegraph/inheritance_processor.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
Instance Method Summary collapse
- #_process ⇒ Object
- #best_fit_name(parent) ⇒ Object
- #fix_parents ⇒ Object
-
#initialize ⇒ InheritanceProcessor
constructor
A new instance of InheritanceProcessor.
- #process(exp) ⇒ Object
- #process_class(exp) ⇒ Object
- #process_colon2(exp) ⇒ Object
- #process_const(exp) ⇒ Object
- #process_module(exp) ⇒ Object
Constructor Details
#initialize ⇒ InheritanceProcessor
Returns a new instance of InheritanceProcessor.
7 8 9 10 11 12 13 |
# File 'lib/codegraph/inheritance_processor.rb', line 7 def initialize super self.strict = false @scopes = [] @classes = {} end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
5 6 7 |
# File 'lib/codegraph/inheritance_processor.rb', line 5 def classes @classes end |
Instance Method Details
#_process ⇒ Object
15 |
# File 'lib/codegraph/inheritance_processor.rb', line 15 alias :_process :process |
#best_fit_name(parent) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/codegraph/inheritance_processor.rb', line 28 def best_fit_name(parent) loop do return parent if @classes.keys.include?(parent) return parent if parent !~ /::/ parent = parent.split('::', 2)[1] end end |
#fix_parents ⇒ Object
22 23 24 25 26 |
# File 'lib/codegraph/inheritance_processor.rb', line 22 def fix_parents @classes.each do |klass, parent| @classes[klass] = best_fit_name(parent) end end |
#process(exp) ⇒ Object
16 17 18 19 20 |
# File 'lib/codegraph/inheritance_processor.rb', line 16 def process(exp) _process(exp) fix_parents classes end |
#process_class(exp) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/codegraph/inheritance_processor.rb', line 48 def process_class(exp) directive, klass, parent = exp[0..2] extra = exp[3..-1] exp.clear add_class atom(klass), atom(parent) @scopes.push klass processed = [directive, klass, parent].concat(extra.map{|e| _process(e)}) @scopes.pop s(*processed) end |
#process_colon2(exp) ⇒ Object
42 43 44 45 46 |
# File 'lib/codegraph/inheritance_processor.rb', line 42 def process_colon2(exp) name = [atom(exp[1]), atom(exp[2])].join('::') exp.clear s(name) end |
#process_const(exp) ⇒ Object
36 37 38 39 40 |
# File 'lib/codegraph/inheritance_processor.rb', line 36 def process_const(exp) name = atom(exp[1]) exp.clear s(name) end |
#process_module(exp) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/codegraph/inheritance_processor.rb', line 62 def process_module(exp) directive, klass = exp[0..1] extra = exp[2..-1] exp.clear @scopes.push klass processed = [directive, klass].concat(extra.map{|e| _process(e)}) @scopes.pop s(*processed) end |