# Module: WpItem::Existable — Documentation by YARD 0.8.6.1

Class List Method List File List

# Module: WpItem::Existable

Included in:
  WpItem
Defined in:
  lib/common/models/wp_item/existable.rb

## Instance Method Summary (collapse)

- - (Boolean) exists?(options = {}, response = nil)

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

- - (Boolean) exists_from_response?(response, options = {}) protected

## Instance Method Details

### - (`Boolean`) exists?(options = {}, response = nil)

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

Parameters:

- options (`Hash`) (defaults to: `{}`) —

  See exists_from_response?

- response (`Typhoeus::Response`) (defaults to: `nil`)

Returns:

- (`Boolean`)

    14
    15
    16
    17
    18
    19

    # File 'lib/common/models/wp_item/existable.rb', line 14

    def exists?(options = {}, response = nil)
      unless response
        response = Browser.get(url)
      end
      exists_from_response?(response, options)
    end

### - (`Boolean`) exists_from_response?(response, options = {}) (protected)

Parameters:

- response (`Typhoeus::Response`)
- options (`options`) (defaults to: `{}`)

Options Hash (`options`):

- :error_404_hash (`Hash`) —

  The hash of the error 404 page

- :homepage_hash (`Hash`) —

  The hash of the homepage

- :exclude_content (`Hash`) —

  A regexp with the pattern to exclude from the body of the response

Returns:

- (`Boolean`)

    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

    # File 'lib/common/models/wp_item/existable.rb', line 31

    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