Class: Gitlab::Triage::Filters::IssueDateConditionsFilter

Inherits:
BaseConditionsFilter show all
Defined in:
lib/gitlab/triage/filters/issue_date_conditions_filter.rb

Direct Known Subclasses

MergeRequestDateConditionsFilter

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

Methods inherited from BaseConditionsFilter

all_params_filter_names, #initialize, params_check_for_field, params_checking_condition_type, params_checking_condition_value, params_filter_names, #validate_condition

Constructor Details

This class inherits a constructor from Gitlab::Triage::Filters::BaseConditionsFilter

Class Method Details

.allowed_attributesObject



16
17
18
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 16

def self.allowed_attributes
  @allowed_attributes ||= generate_allowed_attributes.freeze
end

.filter_parametersObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 20

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_attributesObject



12
13
14
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 12

def self.generate_allowed_attributes
  %w[updated_at created_at]
end

Instance Method Details

#calculateObject

Guard against merge requests with no merged_at values



65
66
67
68
69
70
71
72
73
74
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 65

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_valueObject



56
57
58
59
60
61
62
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 56

def condition_value
  if TIME_BASED_INTERVALS.include?(@interval_type.to_s)
    @interval.public_send(@interval_type).ago.to_datetime # rubocop:disable GitlabSecurity/PublicSend
  else
    @interval.public_send(@interval_type).ago.to_date # rubocop:disable GitlabSecurity/PublicSend
  end
end

#initialize_variables(condition) ⇒ Object



44
45
46
47
48
49
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 44

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_valueObject

Guard against merge requests with no merged_at values



52
53
54
# File 'lib/gitlab/triage/filters/issue_date_conditions_filter.rb', line 52

def resource_value
  @resource[@attribute]&.to_date
end