Class: GetThemAll::GraphBuilder

Inherits:
Extension show all
Defined in:
lib/get_them_all/extensions/graph_builder.rb

Overview

This extension will generate a textfile showing he hierarchy of the site which may be considered as a map.

Its main purpose as a debugging tool to have a better view of what was going on inside.

It was also capable of generating a dot file but this code is not up to date.

Defined Under Namespace

Classes: TreeNode

Instance Method Summary collapse

Methods inherited from Extension

#register_handler

Constructor Details

#initialize(path) ⇒ GraphBuilder

Returns a new instance of GraphBuilder.

Parameters:

  • path (String)

    where the resulting file will be written.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/get_them_all/extensions/graph_builder.rb', line 99

def initialize(path)
  @path = path

  register_handler('downloader.started') do |name, downloader|
    @graph = TreeNode.new("", downloader.base_url)
  end

  register_handler('downloader.completed') do |name, worker, downloader|
    @graph.dump_to_file(@path)
    # @graph.dump_to_dot_file(@path)
  end

  register_handler('action.download.success') do |name, worker, action|
    add_to_graph("D", action.url, action.parent_url)
  end

  register_handler('action.examine.success') do |name, worker, action, returned_actions|
    add_to_graph("E[ret:#{returned_actions.size}]", action.url, action.parent_url)
  end

  register_handler('action.examine.failure') do |name, worker, action, error_status|
    add_to_graph(error_status, action.url, action.referer)
  end

end