Sha256: f27d13009cf5d6cc7d74d059c5e5741f7dc9fdd8ff6e1018457550682e0d0f99

Contents?: true

Size: 1.62 KB

Versions: 16

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module Decidim
  module Exporters
    # This class serializes all components in a ParticipatorySpace so can be
    # exported to CSV, JSON or other formats.
    class ParticipatorySpaceComponentsSerializer < Decidim::Exporters::Serializer
      include Decidim::ApplicationHelper
      include Decidim::ResourceHelper
      include Decidim::TranslationsHelper

      # Public: Initializes the serializer with a participatory_space.
      def initialize(participatory_space)
        @participatory_space = participatory_space
      end

      # Public: Exports a hash with the serialized data for this participatory_space.
      def serialize
        participatory_space.components.collect do |component|
          serialized = {
            manifest_name: component.manifest_name,
            id: component.id,
            name: component.name,
            participatory_space_id: component.participatory_space_id,
            participatory_space_type: component.participatory_space_type,
            settings: component[:settings].as_json,
            weight: component.weight,
            permissions: component.permissions,
            published_at: component.published_at
          }
          serialized[:specific_data] = serialize_component_specific_data(component) if component.serializes_specific_data?
          serialized
        end
      end

      private

      attr_reader :participatory_space

      def serialize_component_specific_data(component)
        specific_serializer = component.manifest.specific_data_serializer_class.new(component)
        specific_serializer.serialize
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-core-0.24.3 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.6 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.24.2 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.5 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.24.1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.24.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.24.0.rc2 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.4 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.24.0.rc1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.3 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.2 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.1.rc1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.23.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.22.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.21.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb