Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_service.rb « award_emojis « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a677d03a2212c11c4a365265ffe1843dfaf86cea (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
30
31
32
# frozen_string_literal: true

module AwardEmojis
  class BaseService < ::BaseService
    attr_accessor :awardable, :name

    def initialize(awardable, name, current_user)
      @awardable = awardable
      @name = normalize_name(name)

      super(awardable.project, current_user)
    end

    private

    def normalize_name(name)
      Gitlab::Emoji.normalize_emoji_name(name)
    end

    # Provide more error state data than what BaseService allows.
    # - An array of errors
    # - The `AwardEmoji` if present
    def error(errors, award: nil, status: nil)
      errors = Array.wrap(errors)

      super(errors.to_sentence.presence, status).merge({
        award: award,
        errors: errors
      })
    end
  end
end