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.



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

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.



32
33
34
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 32

def allowed_attributes
  @allowed_attributes
end

#attributeObject (readonly, private)

Returns the value of attribute attribute.



32
33
34
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 32

def attribute
  @attribute
end

#intervalObject (readonly, private)

Returns the value of attribute interval.



32
33
34
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 32

def interval
  @interval
end

#interval_conditionObject (readonly, private)

Returns the value of attribute interval_condition.



32
33
34
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 32

def interval_condition
  @interval_condition
end

#interval_typeObject (readonly, private)

Returns the value of attribute interval_type.



32
33
34
# File 'lib/gitlab/triage/param_builders/date_param_builder.rb', line 32

def interval_type
  @interval_type
end

Instance Method Details

#filter_parametersObject (private)



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

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



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

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)



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

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