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
15
16
17
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 15
def self.allowed_attributes
self::ATTRIBUTES
end
|
.filter_parameters ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 19
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
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 62
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
54
55
56
57
58
59
60
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 54
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
43
44
45
46
47
48
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 43
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
50
51
52
|
# File 'lib/gitlab/triage/filters/branch_date_filter.rb', line 50
def resource_value
@resource[:commit][@attribute]&.to_date
end
|