Class: ProtectableDropdown

Inherits:
Object
  • Object
show all
Defined in:
app/models/protectable_dropdown.rb

Constant Summary collapse

REF_TYPES =
%i[branches tags].freeze
REF_NAME_METHODS =
{
  branches: :branch_names,
  tags: :tag_names
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(project, ref_type) ⇒ ProtectableDropdown

Returns a new instance of ProtectableDropdown.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'app/models/protectable_dropdown.rb', line 10

def initialize(project, ref_type)
  raise ArgumentError, "invalid ref type `#{ref_type}`" unless ref_type.in?(REF_TYPES)

  @project = project
  @ref_type = ref_type
end

Instance Method Details

#hashObject



24
25
26
# File 'app/models/protectable_dropdown.rb', line 24

def hash
  protectable_ref_names.map { |ref_name| { text: ref_name, id: ref_name, title: ref_name } }
end

#protectable_ref_namesObject

Tags/branches which are yet to be individually protected



18
19
20
21
22
# File 'app/models/protectable_dropdown.rb', line 18

def protectable_ref_names
  return [] if @project.empty_repo?

  @protectable_ref_names ||= ref_names - non_wildcard_protected_ref_names
end