Sha256: 8c58cbf9c988d5d1a57592a09d02997dac3c2c9bd80d317f7462c849e46a97b6

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module Magellan
  module Rake
    # 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
    class BaseMagellanTask < ::Rake::TaskLib
      # The url to start the crawl at
      attr_accessor :origin_url
      # How deep to explore
      attr_accessor :explore_depth
      # An array of urls to not crawl
      attr_accessor :ignored_urls
      # The kind of links you would like 
      attr_accessor :links_to_explore
      # The success message for the task, this is set by the broken link and expected links task.
      attr_accessor :success_message
      # 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
      attr_accessor :failure_log
      
      def initialize(name) # :nodoc:
        @ignored_urls = []
        @name=name
        yield self if block_given?
        define
      end

      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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
magellan-0.1.3 lib/magellan/rake/base_magellan_task.rb