Sha256: d70e0591581780715793a9f80df4d2e6bb3aa1fe2750d92e93f44d7003cdcbcd

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

module PageflowScrolled
  # Register consent vendors based on content element configuration
  # data.
  class ContentElementConsentVendors
    # @api private
    def initialize
      @callables = {}
    end

    # Register callable to determine consent vendor from configuration
    # attributes for a content element type.
    #
    # @param callable [#call]
    #   Receives configuration keyword argument and returns
    # @param content_element_type_name [String]
    def register(callable, content_element_type_name:)
      @callables[content_element_type_name] = callable
    end

    # @api private
    def by_content_element_id(entry)
      content_elements_with_consent_vendor(entry).each_with_object({}) { |content_element, result|
        next unless @callables[content_element.type_name]

        result[content_element.id] = @callables[content_element.type_name].call(
          entry: entry,
          configuration: content_element.configuration
        )
      }.compact
    end

    private

    def content_elements_with_consent_vendor(entry)
      ContentElement.all_for_revision(entry.revision).where(type_name: @callables.keys)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pageflow-17.0.4 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-17.0.3 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-17.0.2 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-17.0.1 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-17.0.0 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-16.2.0 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb
pageflow-16.1.0 entry_types/scrolled/lib/pageflow_scrolled/content_element_consent_vendors.rb