Sha256: 6332403c8e0dbe48ad3647d2d01676863672946bd581f8b2bfbed7e6089f024d

Contents?: true

Size: 808 Bytes

Versions: 74

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true

module Decidim
  #
  # Takes care of holding and serving globally registered manifests.
  #
  class ManifestRegistry
    def initialize(entity)
      @entity = entity
    end

    def register(name)
      manifest = manifest_class.new(name: name.to_sym)
      yield(manifest)
      manifest.validate!
      manifests << manifest
    end

    def manifests
      @manifests ||= Set.new
    end

    def find(name)
      name = name.to_s
      manifests.find do |manifest|
        manifest_name = manifest.name.to_s
        manifest_name == name ||
          manifest.try(:model_class_name) == name ||
          manifest_name.pluralize == name
      end
    end

    private

    def manifest_class
      "Decidim::#{@entity.to_s.classify}Manifest".constantize
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-core-0.25.0.rc4 lib/decidim/manifest_registry.rb
decidim-core-0.25.0.rc3 lib/decidim/manifest_registry.rb
decidim-core-0.25.0.rc2 lib/decidim/manifest_registry.rb
decidim-core-0.25.0.rc1 lib/decidim/manifest_registry.rb
decidim-core-0.24.3 lib/decidim/manifest_registry.rb
decidim-core-0.23.6 lib/decidim/manifest_registry.rb
decidim-core-0.24.2 lib/decidim/manifest_registry.rb
decidim-core-0.23.5 lib/decidim/manifest_registry.rb
decidim-core-0.24.1 lib/decidim/manifest_registry.rb
decidim-core-0.24.0 lib/decidim/manifest_registry.rb
decidim-core-0.24.0.rc2 lib/decidim/manifest_registry.rb
decidim-core-0.23.4 lib/decidim/manifest_registry.rb
decidim-core-0.24.0.rc1 lib/decidim/manifest_registry.rb
decidim-core-0.23.3 lib/decidim/manifest_registry.rb
decidim-core-0.23.2 lib/decidim/manifest_registry.rb
decidim-core-0.23.1 lib/decidim/manifest_registry.rb
decidim-core-0.23.1.rc1 lib/decidim/manifest_registry.rb
decidim-core-0.23.0 lib/decidim/manifest_registry.rb
decidim-core-0.22.0 lib/decidim/manifest_registry.rb
decidim-core-0.21.0 lib/decidim/manifest_registry.rb