Class: Gitlab::CrossProjectAccess::CheckCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/cross_project_access/check_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCheckCollection

Returns a new instance of CheckCollection.


8
9
10
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 8

def initialize
  @checks = []
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks


6
7
8
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 6

def checks
  @checks
end

Instance Method Details

#add_check(check) ⇒ Object


16
17
18
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 16

def add_check(check)
  @checks << check
end

#add_collection(collection) ⇒ Object


12
13
14
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 12

def add_collection(collection)
  @checks |= collection.checks
end

#arranged_checksObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 31

def arranged_checks
  return [@skips, @runs] if @skips && @runs

  @skips = []
  @runs = []

  @checks.each do |check|
    if check.skip
      @skips << check
    else
      @runs << check
    end
  end

  [@skips, @runs]
end

#should_run?(object) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/cross_project_access/check_collection.rb', line 20

def should_run?(object)
  skips, runs = arranged_checks

  # If one rule tells us to skip, we skip the cross project check
  return false if skips.any? { |check| check.should_skip?(object) }

  # If the rule isn't skipped, we run it if any of the checks says we
  # should run
  runs.any? { |check| check.should_run?(object) }
end