Sha256: a59e330279ce508fd279c1342dbac1d9b953948160dc81ecd08feeaafdc19c12

Contents?: true

Size: 1.67 KB

Versions: 6

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 controlling the
  # spidering of links.
  #
  module Actions
    #
    # 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

    protected

    def initialize_actions(options={})
      @paused = false
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
spidr_epg_gem-0.0.1 lib/spidr_epg/actions/actions.rb
spidr_epg_gem-0.0.0 lib/spidr_epg/actions/actions.rb
spidr_epg-1.0.0 lib/spidr/actions/actions.rb
spidr-0.4.1 lib/spidr/actions/actions.rb
spidr-0.4.0 lib/spidr/actions/actions.rb
spidr-0.3.2 lib/spidr/actions/actions.rb