Sha256: 88be44a340324bfda747dc67cb780b89d5e22b6667c3f840f62b7e48555e2b2e

Contents?: true

Size: 1.61 KB

Versions: 17

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Decidim
  module Components
    # This class serves as a DSL to declarative specify which artifacts are
    # exportable in a component. It is used via the `ComponentManifest`.
    #
    class ExportManifest
      attr_reader :name

      # Initializes the manifest.
      #
      # name - The name of the export artifact. It should be unique in the
      #        component.
      #
      def initialize(name)
        @name = name.to_sym
      end

      # Public: Sets the collection when a block is given, or returns it if
      # no block is provided.
      #
      # The collection will get passed an instance of `Decidim::Component` when
      # it's evaluated so you can easily find the elements to export.
      #
      # &block - An optional block that returns the collection once evaluated.
      #
      # Returns the stored collection.
      def collection(&block)
        if block_given?
          @collection = block
        else
          @collection
        end
      end

      # 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.
      def serializer(serializer = nil)
        @serializer ||= serializer || Decidim::Exporters::Serializer
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-core-0.15.2 lib/decidim/components/export_manifest.rb
decidim-core-0.15.1 lib/decidim/components/export_manifest.rb
decidim-core-0.15.0 lib/decidim/components/export_manifest.rb
decidim-core-0.14.4 lib/decidim/components/export_manifest.rb
decidim-core-0.14.3 lib/decidim/components/export_manifest.rb
decidim-core-0.14.2 lib/decidim/components/export_manifest.rb
decidim-core-0.14.1 lib/decidim/components/export_manifest.rb
decidim-core-0.13.1 lib/decidim/components/export_manifest.rb
decidim-core-0.12.2 lib/decidim/components/export_manifest.rb
decidim-core-0.13.0 lib/decidim/components/export_manifest.rb
decidim-core-0.12.1 lib/decidim/components/export_manifest.rb
decidim-core-0.13.0.pre1 lib/decidim/components/export_manifest.rb
decidim-core-0.12.0 lib/decidim/components/export_manifest.rb
decidim-core-0.11.2 lib/decidim/components/export_manifest.rb
decidim-core-0.12.0.pre lib/decidim/components/export_manifest.rb
decidim-core-0.11.1 lib/decidim/components/export_manifest.rb
decidim-core-0.11.0.pre1 lib/decidim/components/export_manifest.rb