Sha256: 4bc68a6e479ebec49f7a0124e6d0f57a72462ab2180c14c38a88ae5093570070

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "json"
require "qonfig"

require_relative "crawler_detect/config"
require_relative "crawler_detect/detector"
require_relative "crawler_detect/library/loader"
require_relative "crawler_detect/library/crawlers"
require_relative "crawler_detect/library/exclusions"
require_relative "crawler_detect/library/headers"
require_relative "crawler_detect/library"
require_relative "crawler_detect/version"
require_relative "rack/crawler_detect"

# @since 0.1.0
module CrawlerDetect
  class << self
    # @param user_agent [String] User-agent string to detect
    # @return [CrawlerDetect::Detector] Instance of detector class
    def new(user_agent)
      detector(user_agent)
    end

    # @param user_agent [String] User-agent string to detect
    # @return [true, false] Is User-agent a crawler?
    def is_crawler?(user_agent)
      detector(user_agent).is_crawler?
    end

    # @since 1.0.0
    # @param config [Proc]
    def setup!(&config)
      @config = CrawlerDetect::Config.new(&config)
      Library.reset_cache
    end

    # @since 1.0.0
    # @return [CrawlerDetect::Config] Instance of configuration class
    def config
      @config ||= CrawlerDetect::Config.new
    end

    private

    def detector(user_agent)
      CrawlerDetect::Detector.new(user_agent)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
crawler_detect-1.2.5 lib/crawler_detect.rb
crawler_detect-1.2.4 lib/crawler_detect.rb
crawler_detect-1.2.3 lib/crawler_detect.rb
crawler_detect-1.2.2 lib/crawler_detect.rb
crawler_detect-1.2.1 lib/crawler_detect.rb
crawler_detect-1.2.0 lib/crawler_detect.rb