gitlab-org--gitlab-foss/lib/gitlab/import_export/reader.rb

41 lines
1.6 KiB
Ruby
Raw Normal View History

module Gitlab
module ImportExport
2016-06-13 15:18:26 -04:00
class Reader
attr_reader :tree
def initialize(shared:)
@shared = shared
config_hash = YAML.load_file(Gitlab::ImportExport.config_file).deep_symbolize_keys
@tree = config_hash[:project_tree]
@attributes_finder = Gitlab::ImportExport::AttributesFinder.new(included_attributes: config_hash[:included_attributes],
2016-05-18 11:48:15 -04:00
excluded_attributes: config_hash[:excluded_attributes],
methods: config_hash[:methods])
end
# Outputs a hash in the format described here: http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
# for outputting a project in JSON format, including its relations and sub relations.
def project_tree
@attributes_finder.find_included(:project).merge(include: build_hash(@tree))
rescue => e
@shared.error(e)
2016-05-16 04:13:00 -04:00
false
end
private
# Builds a hash in the format described here: http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
#
# +model_list+ - List of models as a relation tree to be included in the generated JSON, from the _import_export.yml_ file
def build_hash(model_list)
2016-05-09 12:40:31 -04:00
model_list.map do |model_objects|
if model_objects.is_a?(Hash)
Gitlab::ImportExport::JsonHashBuilder.build(model_objects, @attributes_finder)
2016-04-07 12:14:42 -04:00
else
@attributes_finder.find(model_objects)
2016-04-07 12:14:42 -04:00
end
end
end
end
end
2016-04-08 09:07:12 -04:00
end