favicon.rb 1.1 KB
Newer Older
1 2 3
module Gitlab
  class Favicon
    class << self
4
      def main
5
        return appearance_favicon.favicon_main.url if appearance_favicon.exists?
6

7 8 9 10 11 12 13 14 15 16
        image_name =
          if Gitlab::Utils.to_boolean(ENV['CANARY'])
            'favicon-yellow.png'
          elsif Rails.env.development?
            'favicon-blue.png'
          else
            'favicon.png'
          end

        ActionController::Base.helpers.image_path(image_name)
17 18
      end

19 20 21 22 23 24 25 26 27 28 29
      def status_overlay(status_name)
        path = File.join(
          'ci_favicons',
          "#{status_name}.png"
        )

        ActionController::Base.helpers.image_path(path)
      end

      def available_status_names
        @available_status_names ||= begin
30
          Dir.glob(Rails.root.join('app', 'assets', 'images', 'ci_favicons', '*.png'))
31 32
            .map { |file| File.basename(file, '.png') }
            .sort
33 34 35
        end
      end

36 37 38
      private

      def appearance
39
        RequestStore.store[:appearance] ||= (Appearance.current || Appearance.new)
40 41 42
      end

      def appearance_favicon
43
        appearance.favicon
44 45 46 47
      end
    end
  end
end