# module WpItem::Existable

### Public Instance Methods

exists?(options = {}, response = nil) click to toggle source

Check the existence of the WpItem If the response is supplied, it’s used for the verification Otherwise a new request is done

@param [ Hash ] options See exists_from_response? @param [ Typhoeus::Response ] response

@return [ Boolean ]

    # File lib/common/models/wp_item/existable.rb, line 13
    def exists?(options = {}, response = nil)
      unless response
        response = Browser.get(url)
      end
      exists_from_response?(response, options)
    end

### Protected Instance Methods

exists_from_response?(response, options = {}) click to toggle source

@param [ Typhoeus::Response ] response @param [ options ] options

@option options [ Hash ] :error_404_hash The hash of the error 404 page @option options [ Hash ] :homepage_hash The hash of the homepage @option options [ Hash ] :exclude_content A regexp with the pattern to exclude from the body of the response

@return [ Boolean ]

    # File lib/common/models/wp_item/existable.rb, line 30
    def exists_from_response?(response, options = {})
      if [200, 401, 403].include?(response.code)
        if response.has_valid_hash?(options[:error_404_hash], options[:homepage_hash])
          if options[:exclude_content]
            unless response.body.match(options[:exclude_content])
              return true
            end
          else
            return true
          end
        end
      end
      false
    end