Class: Magellan::Rake::BaseMagellanTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/magellan/rake/base_magellan_task.rb

Overview

The base magellan rake task, defines most attributes associated with running a magellan task TODO: this is not a good place to use a template method - violates Liskov substitution principle

Direct Known Subclasses

BrokenLinkTask, ExpectedLinksTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ BaseMagellanTask

:nodoc:

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
# File 'lib/magellan/rake/base_magellan_task.rb', line 20

def initialize(name) # :nodoc:
  @ignored_urls = []
  @name=name
  yield self if block_given?
  define
end

Instance Attribute Details

#explore_depthObject

How deep to explore



9
10
11
# File 'lib/magellan/rake/base_magellan_task.rb', line 9

def explore_depth
  @explore_depth
end

#failure_logObject

If this is set the logger will log out failures to a file that you specify here, you can tail this log while the crawl is running so you can see what is failing



18
19
20
# File 'lib/magellan/rake/base_magellan_task.rb', line 18

def failure_log
  @failure_log
end

#ignored_urlsObject

An array of urls to not crawl



11
12
13
# File 'lib/magellan/rake/base_magellan_task.rb', line 11

def ignored_urls
  @ignored_urls
end

The kind of links you would like



13
14
15
# File 'lib/magellan/rake/base_magellan_task.rb', line 13

def links_to_explore
  @links_to_explore
end

#origin_urlObject

The url to start the crawl at



7
8
9
# File 'lib/magellan/rake/base_magellan_task.rb', line 7

def origin_url
  @origin_url
end

#success_messageObject

The success message for the task, this is set by the broken link and expected links task.



15
16
17
# File 'lib/magellan/rake/base_magellan_task.rb', line 15

def success_message
  @success_message
end

Instance Method Details

#defineObject

:nodoc:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/magellan/rake/base_magellan_task.rb', line 27

def define # :nodoc:
  desc description
  task @name do
    settings = {:origin_url => origin_url, :depth_to_explore => explore_depth, :domains => [origin_url], 
                :ignored_urls =>ignored_urls, :links_to_explore => links_to_explore, :trace => ENV['TRACE']}
    cartographer = Magellan::Cartographer.new(settings)
    observer = create_observer
    observer.add_observer(Magellan::Logger.new(failure_log))
    cartographer.add_observer(observer)
    cartographer.crawl
    if observer.failed?
      STDERR.puts "\n" + observer.failure_message
      exit 1
    else
      $stdout.puts "\n" + success_message
    end
  end

end