class OpenGraphReader::Configuration

The behavior of this library can be tweaked with some parameters. Note that configuration is global, changing it at runtime is not thread safe.

@example

OpenGraphReader.configure do |config|
  config.strict = true
end

Attributes

discard_invalid_optional_properties[RW]

Discard invalid optional properties (default: false).

Instead of rendering the entire object invalid, discard invalid optional properties.

@return [Bool]

guess_datetime_format[RW]

Parse non ISO8601 datetimes (default: false).

The standard clearly requires ISO8601 as format for datetime properties. However other formats are seen in the wild. With this setting enabled, the format is guessed.

@return [Bool]

strict[RW]

Strict mode (default: false).

In strict mode, if the fetched site defines an unknown type or property, {InvalidObjectError} is thrown instead of just ignoring those.

@return [Bool]

synthesize_full_url[RW]

Guess object URL when it looks like a path (default: false).

The standard requires the url type to point to a full http or https URL. However it's common practice to put a path relative to the domain URL. When enabled, the library tries to guess the full URL from such a path. Note the object can still turn invalid if it fails to do so.

@return [Bool]

synthesize_image_url[RW]

Guess image URL when it looks like a path (default: false).

See {#synthesize_full_url}

@return [Bool]

synthesize_title[RW]

Fallback to the title tag if og:title is missing (default: false).

The standard makes defining og:title required, but it's a common practice to rely on the parser falling back to synthesize it from the title tag. This option enables this feature.

@return [Bool]

synthesize_url[RW]

Return request URL if og:url is missing (default: false).

The standard makes defining og:url required, but it's often missing. This enables a fallback that sets the URL to the request URL if none was found.

@return [Bool]

validate_references[RW]

Validate references (default: true).

If an object should be a reference to another object, validate that it contains an URL. Be careful in turning this off, an attacker could place things like javascript: links there.

@return [Bool]

validate_required[RW]

Validate required (default: true).

Validate that required properties exist. If this is enabled and they do not, {InvalidObjectError} is thrown.

@return [Bool]

Public Class Methods

new() click to toggle source

@private

# File lib/open_graph_reader/configuration.rb, line 95
def initialize
  reset_to_defaults!
end

Public Instance Methods

reset_to_defaults!() click to toggle source

Reset configuration to their defaults

# File lib/open_graph_reader/configuration.rb, line 100
def reset_to_defaults!
  @strict                              = false
  @validate_required                   = true
  @validate_references                 = true
  @discard_invalid_optional_properties = false
  @synthesize_title                    = false
  @synthesize_url                      = false
  @synthesize_full_url                 = false
  @synthesize_image_url                = false
  @guess_datetime_format               = false
end