Class: Decidim::Exporters::ExportManifest
- Inherits:
-
Object
- Object
- Decidim::Exporters::ExportManifest
- Includes:
- ActiveModel::Model
- Defined in:
- lib/decidim/exporters/export_manifest.rb
Overview
This class serves as a DSL to declaratively specify which artifacts are exportable in a parent manifest. A parent manifest is the manifest that will be used by the Serializer to take the settings of the element to serialize. For example a parent manifest may be a ParticipatorySpaceManifest or a ComponentManifest.
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#collection(&block) ⇒ Object
Public: Sets the collection block when a block is given, or returns the previously setted collection block if no block is provided.
-
#initialize(name, manifest) ⇒ ExportManifest
constructor
Initializes the manifest.
-
#serializer(serializer = nil) ⇒ Object
Public: Sets the serializer when an argument is provided, returns the stored serializer otherwise.
Constructor Details
#initialize(name, manifest) ⇒ ExportManifest
Initializes the manifest.
name - The name of the export artifact. It should be unique in the
space or component.
manifest - The parent manifest where this export manifest belongs to.
28 29 30 31 |
# File 'lib/decidim/exporters/export_manifest.rb', line 28 def initialize(name, manifest) @name = name.to_sym @manifest = manifest end |
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
19 20 21 |
# File 'lib/decidim/exporters/export_manifest.rb', line 19 def manifest @manifest end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/decidim/exporters/export_manifest.rb', line 19 def name @name end |
Instance Method Details
#collection(&block) ⇒ Object
Public: Sets the collection block when a block is given, or returns the previously setted collection block if no block is provided.
The collection block knows how to obtain the collection of elements to be serialized by the Serializer
.
The collection block should be invoked like ‘export.collection.call(artifact_type)` and, when evaluated, will get passed an instance of the parent artifact type, `Decidim::ParticipatorySpace` or `Decidim::Component` for example, so you can easily find the elements to export. The collection block in the end should return the collection of elements to be serialized.
&block - An optional block that returns the collection once evaluated.
Returns the stored collection.
49 50 51 52 53 54 55 |
# File 'lib/decidim/exporters/export_manifest.rb', line 49 def collection(&block) if block_given? @collection = block else @collection end end |
#serializer(serializer = nil) ⇒ Object
Public: Sets the serializer when an argument is provided, returns the stored serializer otherwise.
A ‘Serializer` will be run against each and every element of the collection in order to extract and process the relevant fields.
serializer - A subclass of ‘Decidim::Exporters::Serializer`.
Returns the stored serializer if previously stored, or ‘Decidim::Exporters::Serializer` as a default implementation.
67 68 69 |
# File 'lib/decidim/exporters/export_manifest.rb', line 67 def serializer(serializer = nil) @serializer ||= serializer || Decidim::Exporters::Serializer end |