Class: Gitlab::ImportExport::Json::NdjsonWriter

Inherits:
Object
  • Object
show all
Includes:
CommandLineUtil
Defined in:
lib/gitlab/import_export/json/ndjson_writer.rb

Constant Summary

Constants included from CommandLineUtil

CommandLineUtil::CLEAN_DIR_IGNORE_FILE_NAMES, CommandLineUtil::CommandLineUtilError, CommandLineUtil::DEFAULT_DIR_MODE, CommandLineUtil::FileOversizedError, CommandLineUtil::HardLinkError, CommandLineUtil::UNTAR_MASK

Instance Method Summary collapse

Methods included from CommandLineUtil

#gunzip, #gzip, #gzip_with_options, #mkdir_p, #tar_cf, #tar_czf, #untar_xf, #untar_zxf

Constructor Details

#initialize(dir_path) ⇒ NdjsonWriter

Returns a new instance of NdjsonWriter.



9
10
11
# File 'lib/gitlab/import_export/json/ndjson_writer.rb', line 9

def initialize(dir_path)
  @dir_path = dir_path
end

Instance Method Details

#closeObject



13
14
# File 'lib/gitlab/import_export/json/ndjson_writer.rb', line 13

def close
end

#write_attributes(exportable_path, hash) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/gitlab/import_export/json/ndjson_writer.rb', line 16

def write_attributes(exportable_path, hash)
  # It will create:
  # tree/project.json
  with_file("#{exportable_path}.json") do |file|
    file.write(hash.to_json)
  end
end

#write_relation(exportable_path, relation, value) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/gitlab/import_export/json/ndjson_writer.rb', line 24

def write_relation(exportable_path, relation, value)
  # It will create:
  # tree/project/ci_cd_setting.ndjson
  with_file(exportable_path, "#{relation}.ndjson") do |file|
    file.write(value.to_json)
  end
end

#write_relation_array(exportable_path, relation, items) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/import_export/json/ndjson_writer.rb', line 32

def write_relation_array(exportable_path, relation, items)
  # It will create:
  # tree/project/merge_requests.ndjson
  with_file(exportable_path, "#{relation}.ndjson") do |file|
    items.each do |item|
      file.write(item.to_json)
      file.write("\n")
    end
  end
end