Class: Gitlab::Triage::Limiters::DateFieldLimiter

Inherits:
BaseLimiter
  • Object
show all
Defined in:
lib/gitlab/triage/limiters/date_field_limiter.rb

Constant Summary collapse

LIMITS =
%i[most_recent oldest].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseLimiter

#initialize, #validate_limit

Constructor Details

This class inherits a constructor from Gitlab::Triage::Limiters::BaseLimiter

Class Method Details

.limiter_parametersObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 12

def self.limiter_parameters
  [
    {
      name: :most_recent,
      type: Integer
    },
    {
      name: :oldest,
      type: Integer
    }
  ]
end

Instance Method Details

#initialize_resources(resources) ⇒ Object (private)



41
42
43
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 41

def initialize_resources(resources)
  resources.sort_by { |res| res[:created_at] }
end

#initialize_variables(limit) ⇒ Object



25
26
27
28
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 25

def initialize_variables(limit)
  @criterion = LIMITS.find(&limit.method(:[]))
  @threshold = limit[@criterion]
end

#limitObject



30
31
32
33
34
35
36
37
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 30

def limit
  case @criterion
  when :oldest
    @resources.first(@threshold)
  when :most_recent
    @resources.last(@threshold).reverse
  end
end