Sha256: 2ab5c43bb6a43b193218a387b384fba44b205ed3dd17addd1abefc037f8a400c

Contents?: true

Size: 1.07 KB

Versions: 25

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    class ImportExampleForm < Form
      attribute :name, String
      attribute :format, String

      validates :name, presence: true
      validates :format, presence: true
      validates :manifest, presence: true
      validates :reader_klass, presence: true
      validates :example_data, presence: true

      def example
        reader.example_file(example_data)
      end

      def available_formats
        Decidim::Admin::Import::Readers::ACCEPTED_MIME_TYPES
      end

      private

      def manifest
        @manifest ||= current_component.manifest.import_manifests.find do |import_manifest|
          import_manifest.name.to_s == name
        end
      end

      def example_data
        return unless manifest

        manifest.example(self, current_component)
      end

      def reader
        @reader ||= reader_klass ? reader_klass.new("/dev/null") : nil
      end

      def reader_klass
        @reader_klass ||= Decidim::Admin::Import::Readers.search_by_file_extension(format)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.4 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.9 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.29.0 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.8 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.29.0.rc4 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.29.0.rc3 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.29.0.rc2 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.29.0.rc1 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.7 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.6 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.5 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.4 app/forms/decidim/admin/import_example_form.rb
decidim-admin-0.27.3 app/forms/decidim/admin/import_example_form.rb