From 771f73510937186130be260d11b8dbb273d45907 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 13 Jun 2016 09:37:58 +0200 Subject: [PATCH] few more modifications based on comments --- lib/gitlab/import_export.rb | 4 ++++ lib/gitlab/import_export/import_export_reader.rb | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/import_export.rb b/lib/gitlab/import_export.rb index 65a8fcfadd0..cb8b92ed1e8 100644 --- a/lib/gitlab/import_export.rb +++ b/lib/gitlab/import_export.rb @@ -20,6 +20,10 @@ module Gitlab "project.bundle" end + def config_file + 'lib/gitlab/import_export/import_export.yml' + end + def version_filename 'VERSION' end diff --git a/lib/gitlab/import_export/import_export_reader.rb b/lib/gitlab/import_export/import_export_reader.rb index 65d27f4b7a4..c7a44efadf5 100644 --- a/lib/gitlab/import_export/import_export_reader.rb +++ b/lib/gitlab/import_export/import_export_reader.rb @@ -2,17 +2,18 @@ module Gitlab module ImportExport class ImportExportReader - def initialize(config: 'lib/gitlab/import_export/import_export.yml', shared:) + def initialize(shared:) + config = ImportExport.config_file @shared = shared config_hash = YAML.load_file(config).deep_symbolize_keys @tree = config_hash[:project_tree] - @attributes_parser = Gitlab::ImportExport::AttributesFinder.new(included_attributes: config_hash[:included_attributes], + @attributes_finder = Gitlab::ImportExport::AttributesFinder.new(included_attributes: config_hash[:included_attributes], excluded_attributes: config_hash[:excluded_attributes], methods: config_hash[:methods]) end def project_tree - @attributes_parser.find_included(:project).merge(include: build_hash(@tree)) + @attributes_finder.find_included(:project).merge(include: build_hash(@tree)) rescue => e @shared.error(e.message) false @@ -25,7 +26,7 @@ module Gitlab if model_objects.is_a?(Hash) build_json_config_hash(model_objects) else - @attributes_parser.find(model_objects) + @attributes_finder.find(model_objects) end end end @@ -36,7 +37,7 @@ module Gitlab model_object_hash.values.flatten.each do |model_object| current_key = model_object_hash.keys.first - @attributes_parser.parse(current_key) { |hash| @json_config_hash[current_key] ||= hash } + @attributes_finder.parse(current_key) { |hash| @json_config_hash[current_key] ||= hash } handle_model_object(current_key, model_object) process_sub_model(current_key, model_object) if model_object.is_a?(Hash) @@ -66,14 +67,14 @@ module Gitlab def create_model_value(current_key, value) parsed_hash = { include: value } - @attributes_parser.parse(value) do |hash| + @attributes_finder.parse(value) do |hash| parsed_hash = { include: hash_or_merge(value, hash) } end @json_config_hash[current_key] = parsed_hash end def add_model_value(current_key, value) - @attributes_parser.parse(value) { |hash| value = { value => hash } } + @attributes_finder.parse(value) { |hash| value = { value => hash } } old_values = @json_config_hash[current_key][:include] @json_config_hash[current_key][:include] = ([old_values] + [value]).compact.flatten end