Class: Gitlab::Access::BranchProtection
- Inherits:
-
Object
- Object
- Gitlab::Access::BranchProtection
- 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
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #any? ⇒ Boolean
- #developer_can_merge? ⇒ Boolean
- #developer_can_push? ⇒ Boolean
- #fully_protected? ⇒ Boolean
-
#initialize(level) ⇒ BranchProtection
constructor
A new instance of BranchProtection.
Constructor Details
#initialize(level) ⇒ BranchProtection
Returns a new instance of BranchProtection.
25 26 27 |
# File 'lib/gitlab/access/branch_protection.rb', line 25 def initialize(level) @level = level end |
Instance Attribute Details
#level ⇒ Object (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
29 30 31 |
# File 'lib/gitlab/access/branch_protection.rb', line 29 def any? level != PROTECTION_NONE end |
#developer_can_merge? ⇒ 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
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
41 42 43 |
# File 'lib/gitlab/access/branch_protection.rb', line 41 def fully_protected? level == PROTECTION_FULL end |