BigW Consortium Gitlab

protectable_dropdown.rb 695 Bytes
Newer Older
1 2 3 4 5 6 7 8
class ProtectableDropdown
  def initialize(project, ref_type)
    @project = project
    @ref_type = ref_type
  end

  # Tags/branches which are yet to be individually protected
  def protectable_ref_names
9
    @protectable_ref_names ||= ref_names - non_wildcard_protected_ref_names
10 11 12 13 14 15 16 17 18 19 20 21
  end

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

  private

  def refs
    @project.repository.public_send(@ref_type)
  end

22 23 24 25
  def ref_names
    refs.map(&:name)
  end

26 27 28
  def protections
    @project.public_send("protected_#{@ref_type}")
  end
29 30 31 32

  def non_wildcard_protected_ref_names
    protections.reject(&:wildcard?).map(&:name)
  end
33
end