Class: Gitlab::UsageDataCounters::DesignsCounter

Inherits:
Object
  • Object
show all
Extended by:
RedisCounter
Defined in:
lib/gitlab/usage_data_counters/designs_counter.rb

Constant Summary collapse

KNOWN_EVENTS =
%w[create update delete].freeze
UnknownEvent =
Class.new(StandardError)

Class Method Summary collapse

Methods included from RedisCounter

increment, increment_by, total_count

Class Method Details

.count(event) ⇒ Object


19
20
21
# File 'lib/gitlab/usage_data_counters/designs_counter.rb', line 19

def count(event)
  increment(redis_key(event))
end

.fallback_totalsObject


31
32
33
# File 'lib/gitlab/usage_data_counters/designs_counter.rb', line 31

def fallback_totals
  KNOWN_EVENTS.map { |event| [counter_key(event), -1] }.to_h
end

.read(event) ⇒ Object


23
24
25
# File 'lib/gitlab/usage_data_counters/designs_counter.rb', line 23

def read(event)
  total_count(redis_key(event))
end

.redis_key(event) ⇒ Object

Each event gets a unique Redis key

Raises:


13
14
15
16
17
# File 'lib/gitlab/usage_data_counters/designs_counter.rb', line 13

def redis_key(event)
  raise UnknownEvent, event unless KNOWN_EVENTS.include?(event.to_s)

  "USAGE_DESIGN_MANAGEMENT_DESIGNS_#{event}".upcase
end

.totalsObject


27
28
29
# File 'lib/gitlab/usage_data_counters/designs_counter.rb', line 27

def totals
  KNOWN_EVENTS.map { |event| [counter_key(event), read(event)] }.to_h
end