diff options
author | James Lopez <james@jameslopez.es> | 2016-04-06 18:12:41 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-04-06 18:12:41 +0200 |
commit | efde96e9cd4b0096c19ecfa46237b7eda28038aa (patch) | |
tree | c0c9e3186bfb864118e9ba1f58103ef797dc7b2c /app/services | |
parent | e05bc6114491f4c1f84505b4c4746faa8c269420 (diff) | |
download | gitlab-ce-efde96e9cd4b0096c19ecfa46237b7eda28038aa.tar.gz |
started refactored the dynamic rules to be defined in a yml file
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/import_export/import_export.yml | 31 | ||||
-rw-r--r-- | app/services/projects/import_export/import_export_reader.rb | 47 |
2 files changed, 78 insertions, 0 deletions
diff --git a/app/services/projects/import_export/import_export.yml b/app/services/projects/import_export/import_export.yml new file mode 100644 index 00000000000..d02ec5df2ff --- /dev/null +++ b/app/services/projects/import_export/import_export.yml @@ -0,0 +1,31 @@ +# Class relationships to be included in the import/export +:project_tree: + - :issues + - :labels + - :milestones + - :snippets + - :releases + - :events + - :project_members: + - :user + - :merge_requests: + - :merge_request_diff + - :commit_statuses: + - :commit + +:attributes_only: + :project: + - :name + - :path + - :description + - :issues_enabled + - :wall_enabled + - :merge_requests_enabled + - :wiki_enabled + - :snippets_enabled + - :visibility_level + - :archived + :user: + - :id + - :email + - :username
\ No newline at end of file diff --git a/app/services/projects/import_export/import_export_reader.rb b/app/services/projects/import_export/import_export_reader.rb new file mode 100644 index 00000000000..af8c8c3c251 --- /dev/null +++ b/app/services/projects/import_export/import_export_reader.rb @@ -0,0 +1,47 @@ +module Projects + module ImportExport + module ImportExportReader + extend self + + def project_tree + { only: atts_only[:project], include: build_hash(tree) } + end + + def config + @config ||= YAML.load_file('app/services/projects/import_export/import_export.yml') + end + + def atts_only + config[:attributes_only] + end + + def atts_except + config[:attributes_except] + end + + def tree + config[:project_tree] + end + + def build_hash(array) + array.map { |el| el.is_a?(Hash) ? process_include(el) : el } + end + + def process_include(hash) + included_classes_hash = {} + hash.values.flatten.each do |value| + value = value.is_a?(Hash) ? process_include(hash) : value + new_hash = { :include => value } + new_hash.merge!(check_only(value)) + included_classes_hash[hash.keys.first] = new_hash + end + included_classes_hash + end + + def check_only(value) + key = value.is_a?(Hash) ? value.keys.first : value + atts_only[key].nil? ? {} : { only: atts_only[key] } + end + end + end +end
\ No newline at end of file |