Class: OpenGraphReader::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/open_graph_reader/configuration.rb

Overview

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

Examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#discard_invalid_optional_propertiesBool

Discard invalid optional properties (default: false).

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

Returns:

  • (Bool)


47
48
49
# File 'lib/open_graph_reader/configuration.rb', line 47

def discard_invalid_optional_properties
  @discard_invalid_optional_properties
end

#guess_datetime_formatBool

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.

Returns:

  • (Bool)


92
93
94
# File 'lib/open_graph_reader/configuration.rb', line 92

def guess_datetime_format
  @guess_datetime_format
end

#strictBool

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.

Returns:

  • (Bool)


22
23
24
# File 'lib/open_graph_reader/configuration.rb', line 22

def strict
  @strict
end

#synthesize_full_urlBool

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.

Returns:

  • (Bool)


76
77
78
# File 'lib/open_graph_reader/configuration.rb', line 76

def synthesize_full_url
  @synthesize_full_url
end

#synthesize_image_urlBool

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

See #synthesize_full_url

Returns:

  • (Bool)


83
84
85
# File 'lib/open_graph_reader/configuration.rb', line 83

def synthesize_image_url
  @synthesize_image_url
end

#synthesize_titleBool

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.

Returns:

  • (Bool)


56
57
58
# File 'lib/open_graph_reader/configuration.rb', line 56

def synthesize_title
  @synthesize_title
end

#synthesize_urlBool

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.

Returns:

  • (Bool)


65
66
67
# File 'lib/open_graph_reader/configuration.rb', line 65

def synthesize_url
  @synthesize_url
end

#validate_referencesBool

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.

Returns:

  • (Bool)


39
40
41
# File 'lib/open_graph_reader/configuration.rb', line 39

def validate_references
  @validate_references
end

#validate_requiredBool

Validate required (default: true).

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

Returns:

  • (Bool)


30
31
32
# File 'lib/open_graph_reader/configuration.rb', line 30

def validate_required
  @validate_required
end

Instance Method Details

#reset_to_defaults!Object

Reset configuration to their defaults



100
101
102
103
104
105
106
107
108
109
110
# 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