Sha256: 1db75735208cb2deae4bccea207d1cd729eff33ef329930047a370d78d00057b

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

module CMSScanner
  module Finders
    class Finder
      # Module to provide an easy way to enumerate items such as plugins, themes etc
      module Enumerator
        # @param [ Hash ] The target urls
        # @param [ Hash ] opts
        # @option opts [ Boolean ] :show_progression Wether or not to display the progress bar
        # @option opts [ Regexp ] :exclude_content
        #
        # @yield [ Typhoeus::Response, String ]
        def enumerate(target_urls, opts = {})
          create_progress_bar(opts.merge(total: target_urls.size)) # if opts[:show_progression]

          target_urls.each do |url, id|
            request = browser.forge_request(url, request_params)

            request.on_complete do |res|
              progress_bar.increment

              next if target.homepage_or_404?(res)
              next if opts[:exclude_content] && res.body.match(opts[:exclude_content])

              yield res, id
            end

            hydra.queue(request)
          end

          hydra.run
        end

        # @return [ Hash ]
        def request_params
          # disabling the cache, as it causes a 'stack level too deep' exception
          # with a large number of requests :/
          # See https://github.com/typhoeus/typhoeus/issues/408
          { cache_ttl: 0 }
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cms_scanner-0.0.38.4 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.38.3 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.38.2 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.38.1 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.38.0 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.12 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.11 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.10 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.9 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.8 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.7 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.6 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.5 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.4 lib/cms_scanner/finders/finder/enumerator.rb
cms_scanner-0.0.37.3 lib/cms_scanner/finders/finder/enumerator.rb