Class: Decidim::ManifestRegistry
- Inherits:
-
Object
- Object
- Decidim::ManifestRegistry
- Defined in:
- lib/decidim/manifest_registry.rb
Overview
Takes care of holding and serving globally registered manifests.
Instance Method Summary collapse
- #find(name) ⇒ Object
- #find_resource_manifest(resource_name_or_klass) ⇒ Object
-
#initialize(entity) ⇒ ManifestRegistry
constructor
A new instance of ManifestRegistry.
- #manifests ⇒ Object
- #register(name) {|manifest| ... } ⇒ Object
- #resource_manifests ⇒ Object
Constructor Details
#initialize(entity) ⇒ ManifestRegistry
Returns a new instance of ManifestRegistry.
8 9 10 |
# File 'lib/decidim/manifest_registry.rb', line 8 def initialize(entity) @entity = entity end |
Instance Method Details
#find(name) ⇒ Object
23 24 25 |
# File 'lib/decidim/manifest_registry.rb', line 23 def find(name) manifests.find { |manifest| manifest.name == name } end |
#find_resource_manifest(resource_name_or_klass) ⇒ Object
31 32 33 34 35 |
# File 'lib/decidim/manifest_registry.rb', line 31 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 |
#manifests ⇒ Object
19 20 21 |
# File 'lib/decidim/manifest_registry.rb', line 19 def manifests @manifests ||= Set.new end |
#register(name) {|manifest| ... } ⇒ Object
12 13 14 15 16 17 |
# File 'lib/decidim/manifest_registry.rb', line 12 def register(name) manifest = manifest_class.new(name: name.to_sym) yield(manifest) manifest.validate! manifests << manifest end |
#resource_manifests ⇒ Object
27 28 29 |
# File 'lib/decidim/manifest_registry.rb', line 27 def resource_manifests @resource_manifests ||= manifests.flat_map(&:resource_manifests) end |