Sha256: 5b5dc951581cca14179cba0255874a4706c657d17cd04bc3be18cd25a7bacfa3

Contents?: true

Size: 907 Bytes

Versions: 1

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Msad
    module Verification
      class MetadataCollector
        def initialize(saml_attributes)
          @saml_attributes = saml_attributes
        end

        def metadata
          return nil unless Decidim::Msad.metadata_attributes.is_a?(Hash)
          return nil if Decidim::Msad.metadata_attributes.blank?

          collect.delete_if { |_k, v| v.nil? }
        end

        protected

        attr_reader :saml_attributes

        def collect
          Decidim::Msad.metadata_attributes.map do |key, defs|
            value = begin
              case defs
              when Hash
                saml_attributes.public_send(defs[:type], defs[:name])
              when String
                saml_attributes.single(defs)
              end
            end

            [key, value]
          end.to_h
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-msad-0.22.0 lib/decidim/msad/verification/metadata_collector.rb