Class: Gitlab::CrossProjectAccess

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

Defined Under Namespace

Modules: ClassMethods Classes: CheckCollection, CheckInfo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCrossProjectAccess

Returns a new instance of CrossProjectAccess.


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

def initialize
  @checks = {}
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks


14
15
16
# File 'lib/gitlab/cross_project_access.rb', line 14

def checks
  @checks
end

Class Method Details

.instanceObject


10
11
12
# File 'lib/gitlab/cross_project_access.rb', line 10

def self.instance
  @instance ||= new
end

Instance Method Details

#add_check(klass, actions: {}, positive_condition: nil, negative_condition: nil, skip: false) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/cross_project_access.rb', line 20

def add_check(
  klass,
      actions: {},
      positive_condition: nil,
      negative_condition: nil,
      skip: false)

  new_check = CheckInfo.new(actions,
                            positive_condition,
                            negative_condition,
                            skip
                           )

  @checks[klass] ||= Gitlab::CrossProjectAccess::CheckCollection.new
  @checks[klass].add_check(new_check)
  recalculate_checks_for_class(klass)

  @checks[klass]
end

#find_check(object) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/cross_project_access.rb', line 40

def find_check(object)
  @cached_checks ||= Hash.new do |cache, new_class|
    parent_classes = @checks.keys.select { |existing_class| new_class <= existing_class }
    closest_class = closest_parent(parent_classes, new_class)
    cache[new_class] = @checks[closest_class]
  end

  @cached_checks[object.class]
end