Class: Gitlab::Access::BranchProtection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/access/branch_protection.rb

Overview

A wrapper around Integer based branch protection levels.

This wrapper can be used to work with branch protection levels without having to directly refer to the constants. For example, instead of this:

if access_level == Gitlab::Access::PROTECTION_DEV_CAN_PUSH
  ...
end

You can write this instead:

protection = BranchProtection.new(access_level)

if protection.developer_can_push?
  ...
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ BranchProtection

Returns a new instance of BranchProtection.

Parameters:

  • level (Integer)

    The branch protection level as an Integer.


25
26
27
# File 'lib/gitlab/access/branch_protection.rb', line 25

def initialize(level)
  @level = level
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level


22
23
24
# File 'lib/gitlab/access/branch_protection.rb', line 22

def level
  @level
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/gitlab/access/branch_protection.rb', line 29

def any?
  level != PROTECTION_NONE
end

#developer_can_merge?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/gitlab/access/branch_protection.rb', line 37

def developer_can_merge?
  level == PROTECTION_DEV_CAN_MERGE
end

#developer_can_push?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/gitlab/access/branch_protection.rb', line 33

def developer_can_push?
  level == PROTECTION_DEV_CAN_PUSH
end

#fully_protected?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/gitlab/access/branch_protection.rb', line 41

def fully_protected?
  level == PROTECTION_FULL
end