Class: Pageflow::OembedProviders

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/oembed_providers.rb

Overview

Registry for oEmbed providers that can be used to resolve URLs.

Instance Method Summary collapse

Constructor Details

#initializeOembedProviders

Returns a new instance of OembedProviders.



4
5
6
# File 'lib/pageflow/oembed_providers.rb', line 4

def initialize
  @providers = {}
end

Instance Method Details

#find_by_name!(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



27
28
29
30
31
# File 'lib/pageflow/oembed_providers.rb', line 27

def find_by_name!(name)
  @providers.fetch(name.to_s) do
    raise(OembedProviderNotFoundError, "Unknown oEmbed provider '#{name}'")
  end
end

#namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



34
35
36
# File 'lib/pageflow/oembed_providers.rb', line 34

def names
  @providers.keys
end

#register(name, endpoint:, url_patterns:) ⇒ Object

Register an oEmbed provider.

Examples:

config.oembed_providers.register(
  :bluesky,
  endpoint: 'https://bsky.app/oembed.{format}',
  url_patterns: ['https://bsky.app/profile/*/post/*']
)

Parameters:

  • The name of the provider

  • The oEmbed endpoint URL with format placeholder

  • Array of URL patterns the provider can handle



20
21
22
23
24
# File 'lib/pageflow/oembed_providers.rb', line 20

def register(name, endpoint:, url_patterns:)
  provider = OEmbed::Provider.new(endpoint)
  url_patterns.each { |pattern| provider << pattern }
  @providers[name.to_s] = provider
end