summaryrefslogtreecommitdiff
path: root/app/models/snippet_input_action_collection.rb
blob: 1e886e98083ce378528edc285f38ae16af1f0d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

class SnippetInputActionCollection
  include Gitlab::Utils::StrongMemoize

  attr_reader :actions

  delegate :empty?, :any?, :[], to: :actions

  def initialize(actions = [], allowed_actions: nil)
    @actions = actions.map do |action|
      params = action.merge(allowed_actions: allowed_actions)

      SnippetInputAction.new(**params)
    end
  end

  def to_commit_actions
    strong_memoize(:commit_actions) do
      actions.map { |action| action.to_commit_action }
    end
  end

  def valid?
    strong_memoize(:valid) do
      actions.all?(&:valid?)
    end
  end
end