Class: Gitlab::Triage::Filters::BranchDateFilter
Constant Summary
collapse
- ATTRIBUTES =
%w[committed_date authored_date].freeze
- CONDITIONS =
%w[older_than newer_than].freeze
- TIME_BASED_INTERVALS =
%w[minutes hours].freeze
- DATE_BASED_INTERVALS =
%w[days weeks months years].freeze
- INTERVAL_TYPES =
TIME_BASED_INTERVALS + DATE_BASED_INTERVALS
Class Method Summary
collapse
Instance Method Summary
collapse
all_params_filter_names, #initialize, params_check_for_field, params_checking_condition_type, params_checking_condition_value, params_filter_names, #validate_condition
Class Method Details
.allowed_attributes ⇒ Object
13
14
15
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 13
def self.allowed_attributes
self::ATTRIBUTES
end
|
.filter_parameters ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 17
def self.filter_parameters
[
{
name: :attribute,
type: String,
values: allowed_attributes
},
{
name: :condition,
type: String,
values: CONDITIONS
},
{
name: :interval_type,
type: String,
values: INTERVAL_TYPES
},
{
name: :interval,
type: Numeric
}
]
end
|
Instance Method Details
#calculate ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 60
def calculate
return false unless resource_value
case @condition
when :older_than
resource_value < condition_value
when :newer_than
resource_value > condition_value
end
end
|
#condition_value ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 52
def condition_value
if TIME_BASED_INTERVALS.include?(@interval_type.to_s)
@interval.public_send(@interval_type).ago.to_datetime else
@interval.public_send(@interval_type).ago.to_date end
end
|
#initialize_variables(condition) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 41
def initialize_variables(condition)
@attribute = condition[:attribute].to_sym
@condition = condition[:condition].to_sym
@interval_type = condition[:interval_type].to_sym
@interval = condition[:interval]
end
|
#resource_value ⇒ Object
48
49
50
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 48
def resource_value
@resource[:commit][@attribute]&.to_date
end
|