Class: Gitlab::Triage::Filters::IssueDateConditionsFilter
Constant Summary
collapse
- 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
18
19
20
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 18
def self.allowed_attributes
@allowed_attributes ||= generate_allowed_attributes.freeze
end
|
.filter_parameters ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 22
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
|
.generate_allowed_attributes ⇒ Object
14
15
16
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 14
def self.generate_allowed_attributes
%w[updated_at created_at]
end
|
Instance Method Details
#calculate ⇒ Object
Guard against merge requests with no merged_at values
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 67
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
58
59
60
61
62
63
64
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 58
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
46
47
48
49
50
51
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 46
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
Guard against merge requests with no merged_at values
54
55
56
|
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 54
def resource_value
@resource[@attribute]&.to_date
end
|