Class: ReFe::InheritanceGraph
- Inherits:
-
Object
- Object
- ReFe::InheritanceGraph
- Defined in:
- lib/refe/inheritancegraph.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_class_node(name, super_class) ⇒ Object
- #add_include_edge(dest, incl) ⇒ Object
- #ancestors_of(name) ⇒ Object
-
#initialize ⇒ InheritanceGraph
constructor
A new instance of InheritanceGraph.
Constructor Details
#initialize ⇒ InheritanceGraph
Returns a new instance of InheritanceGraph.
32 33 34 35 |
# File 'lib/refe/inheritancegraph.rb', line 32 def initialize @nodes = {} @nodes['Object'] = ClassNode.new('Object', nil) end |
Class Method Details
.parse(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/refe/inheritancegraph.rb', line 17 def InheritanceGraph.parse( path ) graph = new() File.foreach(path) do |line| next if line.sub(/\A\#.*/, '').strip.empty? dest, op, src = line.split case op when '<-' # include graph.add_include_edge dest, src when '<' # inheritance graph.add_class_node dest, src end end graph end |
Instance Method Details
#add_class_node(name, super_class) ⇒ Object
51 52 53 54 |
# File 'lib/refe/inheritancegraph.rb', line 51 def add_class_node( name, super_class ) raise InvalidGraph, "same class given twice: #{name}" if @nodes[name] @nodes[name] = ClassNode.new(name, class_node(super_class)) end |
#add_include_edge(dest, incl) ⇒ Object
45 46 47 48 49 |
# File 'lib/refe/inheritancegraph.rb', line 45 def add_include_edge( dest, incl ) raise InvalidGraph, "include given before definition: #{dest}"\ unless @nodes[dest] @nodes[dest].include module_node(incl) end |
#ancestors_of(name) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/refe/inheritancegraph.rb', line 37 def ancestors_of( name ) if @nodes[name] @nodes[name].ancestors.map {|node| node.name } else [name] end end |