Class: Gitlab::Triage::ParamBuilders::DateParamBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/param_builders/date_param_builder.rb

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowed_attributes, condition_hash) ⇒ DateParamBuilder

Returns a new instance of DateParamBuilder.



14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 14

def initialize(allowed_attributes, condition_hash)
  @allowed_attributes = allowed_attributes
  @attribute = condition_hash[:attribute].to_s
  @interval_condition = condition_hash[:condition].to_sym
  @interval_type = condition_hash[:interval_type]
  @interval = condition_hash[:interval]

  validate_condition(condition_hash)
end

Instance Attribute Details

#allowed_attributesObject (readonly, private)

Returns the value of attribute allowed_attributes.



34
35
36
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 34

def allowed_attributes
  @allowed_attributes
end

#attributeObject (readonly, private)

Returns the value of attribute attribute.



34
35
36
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 34

def attribute
  @attribute
end

#intervalObject (readonly, private)

Returns the value of attribute interval.



34
35
36
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 34

def interval
  @interval
end

#interval_conditionObject (readonly, private)

Returns the value of attribute interval_condition.



34
35
36
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 34

def interval_condition
  @interval_condition
end

#interval_typeObject (readonly, private)

Returns the value of attribute interval_type.



34
35
36
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 34

def interval_type
  @interval_type
end

Instance Method Details

#filter_parametersObject (private)



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 40

def 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

#param_contentObject



24
25
26
27
28
29
30
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 24

def param_content
  if TIME_BASED_INTERVALS.include?(interval_type)
    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

#validate_condition(condition) ⇒ Object (private)



36
37
38
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 36

def validate_condition(condition)
  ParamsValidator.new(filter_parameters, condition).validate!
end