Class: Gitlab::ImportExport::Json::NdjsonReader
- Inherits:
-
Object
- Object
- Gitlab::ImportExport::Json::NdjsonReader
- Defined in:
- lib/gitlab/import_export/json/ndjson_reader.rb
Constant Summary collapse
- MAX_JSON_DOCUMENT_SIZE =
50.megabytes
Instance Attribute Summary collapse
-
#dir_path ⇒ Object
readonly
Returns the value of attribute dir_path.
Instance Method Summary collapse
- #consume_attributes(importable_path) ⇒ Object
- #consume_relation(importable_path, key, mark_as_consumed: true) ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(dir_path) ⇒ NdjsonReader
constructor
A new instance of NdjsonReader.
Constructor Details
#initialize(dir_path) ⇒ NdjsonReader
Returns a new instance of NdjsonReader.
11 12 13 14 |
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 11 def initialize(dir_path) @dir_path = dir_path @consumed_relations = Set.new end |
Instance Attribute Details
#dir_path ⇒ Object (readonly)
Returns the value of attribute dir_path.
9 10 11 |
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 9 def dir_path @dir_path end |
Instance Method Details
#consume_attributes(importable_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 20 def consume_attributes(importable_path) # This reads from `tree/project.json` path = file_path("#{importable_path}.json") if !File.exist?(path) || Gitlab::Utils::FileInfo.linked?(path) raise Gitlab::ImportExport::Error, 'Invalid file' end data = File.read(path, MAX_JSON_DOCUMENT_SIZE) json_decode(data) end |
#consume_relation(importable_path, key, mark_as_consumed: true) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 32 def consume_relation(importable_path, key, mark_as_consumed: true) Enumerator.new do |documents| next if mark_as_consumed && !@consumed_relations.add?("#{importable_path}/#{key}") # This reads from `tree/project/merge_requests.ndjson` path = file_path(importable_path, "#{key}.ndjson") next if !File.exist?(path) || Gitlab::Utils::FileInfo.linked?(path) File.foreach(path, MAX_JSON_DOCUMENT_SIZE).with_index do |line, line_num| documents << [json_decode(line), line_num] end end end |
#exist? ⇒ Boolean
16 17 18 |
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 16 def exist? Dir.exist?(@dir_path) end |