Class: Rumld::Node
Instance Attribute Summary collapse
-
#constant ⇒ Object
readonly
Returns the value of attribute constant.
-
#constant_name ⇒ Object
readonly
Returns the value of attribute constant_name.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #children ⇒ Object
- #children? ⇒ Boolean
- #included_associations_to_dot ⇒ Object
- #included_modules ⇒ Object
- #included_modules_to_dot ⇒ Object
- #inheritence_edge_to_dot ⇒ Object
-
#initialize(tree, constant_name) ⇒ Node
constructor
A new instance of Node.
- #node_to_dot ⇒ Object
- #self_and_descendants ⇒ Object
-
#should_be_parent_of?(other_constant_name) ⇒ Boolean
I only want constants that are one module level deeper than the current constant_name.
Constructor Details
#initialize(tree, constant_name) ⇒ Node
Returns a new instance of Node.
10 11 12 13 |
# File 'lib/rumld/node.rb', line 10 def initialize(tree, constant_name) @constant_name = constant_name @tree = tree end |
Instance Attribute Details
#constant ⇒ Object (readonly)
Returns the value of attribute constant.
3 4 5 |
# File 'lib/rumld/node.rb', line 3 def constant @constant end |
#constant_name ⇒ Object (readonly)
Returns the value of attribute constant_name.
3 4 5 |
# File 'lib/rumld/node.rb', line 3 def constant_name @constant_name end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
3 4 5 |
# File 'lib/rumld/node.rb', line 3 def tree @tree end |
Instance Method Details
#children ⇒ Object
60 61 62 |
# File 'lib/rumld/node.rb', line 60 def children @children ||= [] end |
#children? ⇒ Boolean
64 65 66 |
# File 'lib/rumld/node.rb', line 64 def children? !children.empty? end |
#included_associations_to_dot ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rumld/node.rb', line 39 def included_associations_to_dot active_record_associations.collect do |assoc| case assoc.macro.to_s when 'belongs_to' then to_dot_for_belongs_to(assoc) when 'has_one' then has_one_to_dot(assoc) when 'has_many' then has_many_to_dot(assoc) when 'has_and_belongs_to_many' then habtm_to_dot(assoc) end end end |
#included_modules ⇒ Object
68 69 70 |
# File 'lib/rumld/node.rb', line 68 def included_modules rdoc_inspector.all_included_modules & tree.constant_names end |
#included_modules_to_dot ⇒ Object
50 51 52 53 54 |
# File 'lib/rumld/node.rb', line 50 def included_modules_to_dot included_modules.collect do |mod| %("#{constant_name}" -> "#{mod}" [style=dotted, arrowhead=empty]) end end |
#inheritence_edge_to_dot ⇒ Object
33 34 35 36 37 |
# File 'lib/rumld/node.rb', line 33 def inheritence_edge_to_dot if constant.respond_to?(:superclass) && ancestor_node = tree.node_for(constant.superclass) %("#{constant_name}" -> "#{ancestor_node.constant_name}" [arrowhead=empty]) end end |
#node_to_dot ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rumld/node.rb', line 19 def node_to_dot if children? children.sort!{|a,b| a.constant_name <=> b.constant_name} %(subgraph cluster#{detached_constant_name} { label = "#{detached_constant_name}"; color = grey; #{self_to_dot(:style=>"dotted")} #{children.collect{|n| n.node_to_dot}.join("\n")} }) else self_to_dot end end |
#self_and_descendants ⇒ Object
56 57 58 |
# File 'lib/rumld/node.rb', line 56 def self_and_descendants ([self] + children.collect{|n| n.self_and_descendants}).flatten end |
#should_be_parent_of?(other_constant_name) ⇒ Boolean
I only want constants that are one module level deeper than the current constant_name
74 75 76 77 78 79 80 |
# File 'lib/rumld/node.rb', line 74 def should_be_parent_of?(other_constant_name) if match = other_constant_name.match(/^#{Regexp.escape(constant_name + '::')}/) %(#{match}#{other_constant_name.split('::').last}) == other_constant_name else false end end |