Sha256: dbe97cd3570d48d734e612da932ddc1dee7660029574ed6a2dbe327b573ed82b

Contents?: true

Size: 794 Bytes

Versions: 36

Compression:

Stored size: 794 Bytes

Contents

module Pageflow
  module EntryExportImport
    class FileMappings
      def initialize
        @file_mappings = {}
      end

      def find_or_store(exported_file_id, file_type)
        imported_file_id = @file_mappings.dig(file_type.model.name, exported_file_id)

        if imported_file_id.present?
          imported_file_id
        else
          file = yield

          @file_mappings[file_type.model.name] ||= {}
          @file_mappings[file_type.model.name][exported_file_id] = file.id

          file.id
        end
      end

      def imported_id_for(model_name, exported_id)
        @file_mappings.fetch(model_name)[exported_id]
      end

      def exported_id_for(model_name, imported_id)
        @file_mappings.fetch(model_name).invert[imported_id]
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
pageflow-15.1.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.rc0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta6 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta5 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta4 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta3 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta2 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.0.beta1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.2 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.0.rc2 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.0.rc1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.0.beta4 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.0.0.beta3 lib/pageflow/entry_export_import/file_mappings.rb