Sha256: 3176ff53cb01dd5a059d7c8e61796bf7fc9ec42c33cb7237ec671d8114222aba

Contents?: true

Size: 760 Bytes

Versions: 4

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

module MediaTypes
  INTEGRATION_METHODS = %i[register].freeze

  module_function

  def integrate(integration)
    INTEGRATION_METHODS.each do |method|
      next unless integration.respond_to?(method)
      self.integrations = (integrations || {}).tap do |x|
        x.merge!(method => (x[method] || []).concat([integration]))
      end
    end
  end

  # @!method register(registerable)
  INTEGRATION_METHODS.each do |method|
    define_singleton_method method do |*args, &block|
      (integrations || {}).fetch(method) { [] }.each do |integration|
        integration.send(method, *args, &block)
      end
    end

  end

  class << self
    private

    attr_accessor :integrations
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
media_types-1.0.0 lib/media_types/integrations.rb
media_types-0.6.2 lib/media_types/integrations.rb
media_types-0.6.1 lib/media_types/integrations.rb
media_types-0.6.0 lib/media_types/integrations.rb