Class: Gitlab::Triage::Limiters::DateFieldLimiter
- Inherits:
-
BaseLimiter
- Object
- BaseLimiter
- Gitlab::Triage::Limiters::DateFieldLimiter
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
Class Method Details
.limiter_parameters ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 10
def self.limiter_parameters
[
{
name: :most_recent,
type: Integer
},
{
name: :oldest,
type: Integer
}
]
end
|
Instance Method Details
#initialize_resources(resources) ⇒ Object
39
40
41
|
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 39
def initialize_resources(resources)
resources.sort_by { |res| res[:created_at] }
end
|
#initialize_variables(limit) ⇒ Object
23
24
25
26
|
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 23
def initialize_variables(limit)
@criterion = LIMITS.find(&limit.method(:[]))
@threshold = limit[@criterion]
end
|
#limit ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/gitlab/triage/limiters/date_field_limiter.rb', line 28
def limit
case @criterion
when :oldest
@resources.first(@threshold)
when :most_recent
@resources.last(@threshold).reverse
end
end
|