Sha256: cb6c0f142a11d11285e6dd490da56dbb635e33d68041301f40798eb563690e9e

Contents?: true

Size: 1.65 KB

Versions: 44

Compression:

Stored size: 1.65 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
      alias resource participatory_space

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.4 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.27.9 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.29.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.3 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.27.8 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.29.0.rc4 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.29.0.rc3 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.29.0.rc2 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.29.0.rc1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.2 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.27.7 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.1 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.27.6 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.26.10 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.26.9 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.0 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.27.5 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.0.rc5 app/serializers/decidim/exporters/participatory_space_components_serializer.rb
decidim-core-0.28.0.rc4 app/serializers/decidim/exporters/participatory_space_components_serializer.rb