Class: Dread::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/dread/graph.rb

Constant Summary collapse

INDENT_INCREASE =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz, indent = 0, pluralized = false) ⇒ Graph

Returns a new instance of Graph.



10
11
12
13
14
# File 'lib/dread/graph.rb', line 10

def initialize(clazz, indent=0, pluralized=false)
  set_and_verify_clazz(clazz)
  @indent = indent
  @pluralized = pluralized
end

Instance Attribute Details

#clazzObject (readonly)

Returns the value of attribute clazz.



8
9
10
# File 'lib/dread/graph.rb', line 8

def clazz
  @clazz
end

#indentObject (readonly)

Returns the value of attribute indent.



8
9
10
# File 'lib/dread/graph.rb', line 8

def indent
  @indent
end

#pluralizedObject (readonly)

Returns the value of attribute pluralized.



8
9
10
# File 'lib/dread/graph.rb', line 8

def pluralized
  @pluralized
end

Instance Method Details

#drawObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dread/graph.rb', line 16

def draw
  puts " " * indent + clazz_name()

  @clazz.reflections.each do |assoc_name, assoc_data|
    if assoc_data.options[:dependent] == :delete
      puts " "*(indent+INDENT_INCREASE) + "#{assoc_name} [#{assoc_data.table_name.classify}]"
    elsif assoc_data.options[:dependent] == :destroy
      Graph.new(assoc_data.table_name, indent + INDENT_INCREASE, pluralized = true).draw
    end
  end
end