summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-06-19 09:54:47 +0200
committerJames Lopez <james@jameslopez.es>2018-06-19 09:54:47 +0200
commitb99bc6d38088b7b87f6ffa4a706ab5eacb489449 (patch)
treeca0f8f678f062ab524278d5c768e892603039c16 /lib
parente0c06470f48d9e0f3a3175582134f40baf15d624 (diff)
downloadgitlab-ce-b99bc6d38088b7b87f6ffa4a706ab5eacb489449.tar.gz
add group finder spec and logic
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/import_export/group_project_finder.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/import_export/group_project_finder.rb b/lib/gitlab/import_export/group_project_finder.rb
new file mode 100644
index 00000000000..d2d4898f6bc
--- /dev/null
+++ b/lib/gitlab/import_export/group_project_finder.rb
@@ -0,0 +1,33 @@
+module Gitlab
+ module ImportExport
+ class GroupProjectFinder
+ def self.find(*args)
+ new(*args).find
+ end
+
+ def initialize(klass, attributes)
+ @klass = klass
+ @attributes = attributes
+ @group_id = @attributes['group_id']
+ @project_id = @attributes['project_id']
+ end
+
+ def find
+ @klass.where(where_clause)
+ end
+
+ private
+
+ def where_clause
+ @attributes.except('group_id', 'project_id').map do |key, value|
+ table[key].eq(value).and(table[:group_id].eq(@group_id))
+ .or(table[key].eq(value).and(table[:project_id].eq(@project_id)))
+ end.reduce(:or)
+ end
+
+ def table
+ @table ||= @klass.arel_table
+ end
+ end
+ end
+end