2012-11-05 19:12:26 +01:00
|
|
|
class EventFilter
|
|
|
|
attr_accessor :params
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def default_filter
|
|
|
|
%w{ push issues merge_requests team}
|
|
|
|
end
|
|
|
|
|
|
|
|
def push
|
|
|
|
'push'
|
|
|
|
end
|
|
|
|
|
|
|
|
def merged
|
|
|
|
'merged'
|
|
|
|
end
|
|
|
|
|
|
|
|
def comments
|
|
|
|
'comments'
|
|
|
|
end
|
|
|
|
|
|
|
|
def team
|
|
|
|
'team'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize params
|
|
|
|
@params = if params
|
|
|
|
params.dup
|
|
|
|
else
|
|
|
|
[]#EventFilter.default_filter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def apply_filter events
|
|
|
|
return events unless params.present?
|
|
|
|
|
|
|
|
filter = params.dup
|
|
|
|
|
|
|
|
actions = []
|
2013-02-13 12:48:16 +01:00
|
|
|
actions << Event::PUSHED if filter.include? 'push'
|
|
|
|
actions << Event::MERGED if filter.include? 'merged'
|
2012-11-05 19:12:26 +01:00
|
|
|
|
|
|
|
if filter.include? 'team'
|
2013-02-13 12:48:16 +01:00
|
|
|
actions << Event::JOINED
|
|
|
|
actions << Event::LEFT
|
2012-11-05 19:12:26 +01:00
|
|
|
end
|
|
|
|
|
2013-02-13 12:48:16 +01:00
|
|
|
actions << Event::COMMENTED if filter.include? 'comments'
|
2012-11-05 19:12:26 +01:00
|
|
|
|
|
|
|
events = events.where(action: actions)
|
|
|
|
end
|
|
|
|
|
|
|
|
def options key
|
|
|
|
filter = params.dup
|
|
|
|
|
|
|
|
if filter.include? key
|
|
|
|
filter.delete key
|
|
|
|
else
|
|
|
|
filter << key
|
|
|
|
end
|
|
|
|
|
|
|
|
filter
|
|
|
|
end
|
|
|
|
|
|
|
|
def active? key
|
|
|
|
params.include? key
|
|
|
|
end
|
|
|
|
end
|