Class: OpenGraphReader::Configuration
- Inherits:
-
Object
- Object
- OpenGraphReader::Configuration
- 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.
Instance Attribute Summary collapse
-
#discard_invalid_optional_properties ⇒ Bool
Discard invalid optional properties (default:
false). -
#guess_datetime_format ⇒ Bool
Parse non ISO8601 datetimes (default:
false). -
#strict ⇒ Bool
Strict mode (default:
false). -
#synthesize_full_url ⇒ Bool
Guess object URL when it looks like a path (default:
false). -
#synthesize_image_url ⇒ Bool
Guess image URL when it looks like a path (default:
false). -
#synthesize_title ⇒ Bool
Fallback to the title tag if og:title is missing (default:
false). -
#synthesize_url ⇒ Bool
Return request URL if og:url is missing (default:
false). -
#validate_references ⇒ Bool
Validate references (default:
true). -
#validate_required ⇒ Bool
Validate required (default:
true).
Instance Method Summary collapse
-
#reset_to_defaults! ⇒ Object
Reset configuration to their defaults.
Instance Attribute Details
#discard_invalid_optional_properties ⇒ Bool
Discard invalid optional properties (default: false).
Instead of rendering the entire object invalid, discard invalid optional properties.
47 48 49 |
# File 'lib/open_graph_reader/configuration.rb', line 47 def discard_invalid_optional_properties @discard_invalid_optional_properties end |
#guess_datetime_format ⇒ Bool
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.
92 93 94 |
# File 'lib/open_graph_reader/configuration.rb', line 92 def guess_datetime_format @guess_datetime_format end |
#strict ⇒ Bool
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.
22 23 24 |
# File 'lib/open_graph_reader/configuration.rb', line 22 def strict @strict end |
#synthesize_full_url ⇒ Bool
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.
76 77 78 |
# File 'lib/open_graph_reader/configuration.rb', line 76 def synthesize_full_url @synthesize_full_url end |
#synthesize_image_url ⇒ Bool
Guess image URL when it looks like a path (default: false).
83 84 85 |
# File 'lib/open_graph_reader/configuration.rb', line 83 def synthesize_image_url @synthesize_image_url end |
#synthesize_title ⇒ Bool
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.
56 57 58 |
# File 'lib/open_graph_reader/configuration.rb', line 56 def synthesize_title @synthesize_title end |
#synthesize_url ⇒ Bool
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.
65 66 67 |
# File 'lib/open_graph_reader/configuration.rb', line 65 def synthesize_url @synthesize_url end |
#validate_references ⇒ Bool
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.
39 40 41 |
# File 'lib/open_graph_reader/configuration.rb', line 39 def validate_references @validate_references end |
#validate_required ⇒ Bool
Validate required (default: true).
Validate that required properties exist. If this is enabled and they do not, InvalidObjectError is thrown.
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 |