Sha256: cf5daa3769e885273a7a520168aa778f9ebab8c12b39b35ff32f88fed8e7a3e4

Contents?: true

Size: 640 Bytes

Versions: 13

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true

module OembedProxy
  # Generic composing handler
  class Handler
    def initialize(*providers)
      @registered_providers = providers
    end

    def register(provider)
      @registered_providers << provider
    end

    def handles_url?(url)
      !provider_for_url(url).nil?
    end

    def get_data(url, other_params = {})
      provider = provider_for_url(url)
      return provider.get_data(url, other_params) unless provider.nil?
    end

    private

    def provider_for_url(url)
      # TODO: Switch to #find
      @registered_providers.select { |p| p.handles_url? url }.first
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
oembed_proxy-0.3 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.6 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.5 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.4 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.3 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.2 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.1 lib/oembed_proxy/handler.rb
oembed_proxy-0.2.0 lib/oembed_proxy/handler.rb
oembed_proxy-0.1.4 lib/oembed_proxy/handler.rb
oembed_proxy-0.1.3 lib/oembed_proxy/handler.rb
oembed_proxy-0.1.2 lib/oembed_proxy/handler.rb
oembed_proxy-0.1.1 lib/oembed_proxy/handler.rb
oembed_proxy-0.1.0 lib/oembed_proxy/handler.rb