diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/import_export/group_project_finder.rb | 33 |
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 |