Top Level Namespace

Defined Under Namespace

Modules: YARD

Instance Method Summary collapse

Instance Method Details

#initObject



3
4
5
6
# File 'lib/yard-state_machine/yard/state_machine/templates/default/class/html/setup.rb', line 3

def init
  super
  sections.place(:state_machine_details).before(:children)
end

#render_state_machine_data(state_machines) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/yard-state_machine/yard/state_machine/templates/default/class/html/setup.rb', line 19

def render_state_machine_data state_machines

  state_machine_image_paths = Hash.new

  images_base_path = File.dirname(serializer.serialized_path(object))

  state_machines.each do |state_machine_name, state_machine|

    image_file_name = object.name.to_s + '_' + state_machine_name + '.png'

    image_path = File.join(images_base_path, image_file_name)

    content = GraphViz.new(:G, :type => :digraph) do |graph|

      state_machine[:description][:events].each do |event_name, event|

        event[:description][:transitions].each do |transition|

          to_state = graph.add_node(transition[:to_state].to_s)

          transition[:from_states].each do |state|
            from_state = graph.add_node(state.to_s)
            link = graph.add_edge(from_state, to_state)
            link.label = event[:name].to_s
          end

        end

      end

    end.output(:png => String)

    serializer.serialize(image_path, content)

    state_machine_image_paths[state_machine_name] = image_path
  end

  return state_machine_image_paths

end

#state_machine_detailsObject



8
9
10
11
12
13
14
15
16
# File 'lib/yard-state_machine/yard/state_machine/templates/default/class/html/setup.rb', line 8

def state_machine_details
  @state_machines = object['state_machine_state_machines']

  return unless @state_machines

  @state_machine_image_objects = render_state_machine_data(@state_machines)

  erb(:state_machine_details)
end