Class: EventFilter

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/event_filter.rb

Constant Summary collapse

ALL =
'all'
PUSH =
'push'
MERGED =
'merged'
ISSUE =
'issue'
COMMENTS =
'comments'
TEAM =
'team'
WIKI =
'wiki'
DESIGNS =
'designs'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(filter) ⇒ EventFilter

Returns a new instance of EventFilter.


17
18
19
20
21
# File 'lib/event_filter.rb', line 17

def initialize(filter)
  # Split using comma to maintain backward compatibility Ex/ "filter1,filter2"
  filter = filter.to_s.split(',')[0].to_s
  @filter = filters.include?(filter) ? filter : ALL
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter


6
7
8
# File 'lib/event_filter.rb', line 6

def filter
  @filter
end

Instance Method Details

#active?(key) ⇒ Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/event_filter.rb', line 23

def active?(key)
  filter == key.to_s
end

#apply_filter(events) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/event_filter.rb', line 28

def apply_filter(events)
  case filter
  when PUSH
    events.pushed_action
  when MERGED
    events.merged_action
  when COMMENTS
    events.commented_action
  when TEAM
    events.where(action: [:joined, :left, :expired])
  when ISSUE
    events.where(action: [:created, :updated, :closed, :reopened], target_type: 'Issue')
  when WIKI
    wiki_events(events)
  when DESIGNS
    design_events(events)
  else
    events
  end
end