Class: Gitlab::Triage::Filters::DiscussionsConditionsFilter

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

Constant Summary collapse

ATTRIBUTES =
%w[notes threads].freeze
CONDITIONS =
%w[greater_than less_than].freeze

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

.filter_parametersObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/triage/filters/discussions_conditions_filter.rb', line 12

def self.filter_parameters
  [
    {
      name: :attribute,
      type: String,
      values: ATTRIBUTES
    },
    {
      name: :condition,
      type: String,
      values: CONDITIONS
    },
    {
      name: :threshold,
      type: Numeric
    }
  ]
end

Instance Method Details

#calculateObject



49
50
51
52
53
54
55
56
# File 'lib/gitlab/triage/filters/discussions_conditions_filter.rb', line 49

def calculate
  case @condition
  when :greater_than
    resource_value.to_i > condition_value
  when :less_than
    resource_value.to_i < condition_value
  end
end

#condition_valueObject



45
46
47
# File 'lib/gitlab/triage/filters/discussions_conditions_filter.rb', line 45

def condition_value
  @threshold
end

#initialize_variables(condition) ⇒ Object



31
32
33
34
35
# File 'lib/gitlab/triage/filters/discussions_conditions_filter.rb', line 31

def initialize_variables(condition)
  @attribute = condition[:attribute].to_sym
  @condition = condition[:condition].to_sym
  @threshold = condition[:threshold]
end

#resource_valueObject



37
38
39
40
41
42
43
# File 'lib/gitlab/triage/filters/discussions_conditions_filter.rb', line 37

def resource_value
  if @attribute == :notes
    @resource[:user_notes_count]
  else
    @resource[:user_discussions_count]
  end
end