Class: Magellan::Rake::BaseMagellanTask

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

Direct Known Subclasses

BrokenLinkTask, ExpectedLinksTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BaseMagellanTask.

Yields:

  • (_self)

Yield Parameters:



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

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

Instance Attribute Details

#explore_depthObject

Returns the value of attribute explore_depth.



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

def explore_depth
  @explore_depth
end

#failure_logObject

Returns the value of attribute failure_log.



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

def failure_log
  @failure_log
end

#ignored_urlsObject

Returns the value of attribute ignored_urls.



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

def ignored_urls
  @ignored_urls
end

Returns the value of attribute links_to_explore.



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

def links_to_explore
  @links_to_explore
end

#origin_urlObject

Returns the value of attribute origin_url.



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

def origin_url
  @origin_url
end

#success_messageObject

Returns the value of attribute success_message.



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

def success_message
  @success_message
end

Instance Method Details

#defineObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/magellan/rake/base_magellan_task.rb', line 20

def define
  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