Sha256: 56a4066901761905e887fadba3a51fd86d9b2b23115253c3afedaddda6294c2e

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require 'spidr/actions/exceptions/paused'
require 'spidr/actions/exceptions/skip_link'
require 'spidr/actions/exceptions/skip_page'

module Spidr
  #
  # The {Actions} module adds methods to {Agent} for controling the
  # spidering of links.
  #
  module Actions
    def initialize(options={})
      @paused = false

      super(options)
    end

    #
    # Continue spidering.
    #
    # @yield [page]
    #   If a block is given, it will be passed every page visited.
    #
    # @yieldparam [Page] page
    #   The page to be visited.
    #
    def continue!(&block)
      @paused = false
      return run(&block)
    end

    #
    # Sets the pause state of the agent.
    #
    # @param [Boolean] state
    #   The new pause state of the agent.
    #
    def pause=(state)
      @paused = state
    end

    #
    # Pauses the agent, causing spidering to temporarily stop.
    #
    # @raise [Paused]
    #   Indicates to the agent, that it should pause spidering.
    #
    def pause!
      @paused = true
      raise(Paused)
    end

    #
    # Determines whether the agent is paused.
    #
    # @return [Boolean]
    #   Specifies whether the agent is paused.
    #
    def paused?
      @paused == true
    end

    #
    # Causes the agent to skip the link being enqueued.
    #
    # @raise [SkipLink]
    #   Indicates to the agent, that the current link should be skipped,
    #   and not enqueued or visited.
    #
    def skip_link!
      raise(SkipLink)
    end

    #
    # Causes the agent to skip the page being visited.
    #
    # @raise [SkipPage]
    #   Indicates to the agent, that the current page should be skipped.
    #
    def skip_page!
      raise(SkipPage)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spidr-0.2.7 lib/spidr/actions/actions.rb
spidr-0.2.6 lib/spidr/actions/actions.rb
spidr-0.2.5 lib/spidr/actions/actions.rb
spidr-0.2.4 lib/spidr/actions/actions.rb
spidr-0.2.3 lib/spidr/actions/actions.rb