summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/attributes_finder.rb
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-05-06 17:55:06 +0200
committerJames Lopez <james@jameslopez.es>2016-05-06 17:55:06 +0200
commit8ac53eb5d0dcc6d0248a8b178a3c1b5f2d2284e1 (patch)
tree1e2da8799bb8e20fb92343bce6ac67fc9fa21546 /lib/gitlab/import_export/attributes_finder.rb
parentb6ab4a311396d12cdb686df885fe48c58ea31218 (diff)
downloadgitlab-ce-8ac53eb5d0dcc6d0248a8b178a3c1b5f2d2284e1.tar.gz
started refactoring import export reader - WIP
Diffstat (limited to 'lib/gitlab/import_export/attributes_finder.rb')
-rw-r--r--lib/gitlab/import_export/attributes_finder.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/import_export/attributes_finder.rb b/lib/gitlab/import_export/attributes_finder.rb
new file mode 100644
index 00000000000..12ae79a8773
--- /dev/null
+++ b/lib/gitlab/import_export/attributes_finder.rb
@@ -0,0 +1,35 @@
+module Gitlab
+ module ImportExport
+ class AttributesFinder
+ def initialize(included_attributes:, excluded_attributes:)
+ @included_attributes = included_attributes || {}
+ @excluded_attributes = excluded_attributes || {}
+ end
+
+ def find(model_object)
+ parsed_hash = find_attributes_only(model_object)
+ parsed_hash.empty? ? model_object : { model_object => parsed_hash }
+ end
+
+ def find_attributes_only(value)
+ find_included(value).merge(find_excluded(value))
+ end
+
+ def find_included(value)
+ key = key_from_hash(value)
+ @included_attributes[key].nil? ? {} : { only: @included_attributes[key] }
+ end
+
+ def find_excluded(value)
+ key = key_from_hash(value)
+ @excluded_attributes[key].nil? ? {} : { except: @excluded_attributes[key] }
+ end
+
+ private
+
+ def key_from_hash(value)
+ value.is_a?(Hash) ? value.keys.first : value
+ end
+ end
+ end
+end \ No newline at end of file