Sha256: 5d1fd8cc6d9593b559757c4766b960b8a27366d2941b26248c58a1ed3d291385

Contents?: true

Size: 960 Bytes

Versions: 37

Compression:

Stored size: 960 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)
      manifests.find { |manifest| manifest.name == name }
    end

    def resource_manifests
      @resource_manifests ||= manifests.flat_map(&:resource_manifests)
    end

    def find_resource_manifest(resource_name_or_klass)
      resource_manifests.find do |manifest|
        manifest.model_class == resource_name_or_klass || manifest.name.to_s == resource_name_or_klass.to_s
      end
    end

    private

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

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
decidim-0.6.8 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.7 lib/decidim/manifest_registry.rb
decidim-0.6.7 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.6 lib/decidim/manifest_registry.rb
decidim-0.6.6 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.5 lib/decidim/manifest_registry.rb
decidim-0.6.5 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.4 lib/decidim/manifest_registry.rb
decidim-0.6.4 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.3 lib/decidim/manifest_registry.rb
decidim-0.6.3 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.2 lib/decidim/manifest_registry.rb
decidim-0.6.2 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.1 lib/decidim/manifest_registry.rb
decidim-0.6.1 decidim-core/lib/decidim/manifest_registry.rb
decidim-core-0.6.0 lib/decidim/manifest_registry.rb
decidim-0.6.0 decidim-core/lib/decidim/manifest_registry.rb