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-17.0.4 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-17.0.3 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-17.0.2 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-17.0.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-17.0.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-16.2.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-16.1.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-16.0.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.8.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.7.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.7.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.6.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.6.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.5.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.4.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.3.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.2.2 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.2.1 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.2.0 lib/pageflow/entry_export_import/file_mappings.rb
pageflow-15.1.2 lib/pageflow/entry_export_import/file_mappings.rb