Class: Gitlab::Triage::ParamBuilders::DateParamBuilder
- Inherits:
-
Object
- Object
- Gitlab::Triage::ParamBuilders::DateParamBuilder
- 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
-
#allowed_attributes ⇒ Object
readonly
private
Returns the value of attribute allowed_attributes.
-
#attribute ⇒ Object
readonly
private
Returns the value of attribute attribute.
-
#interval ⇒ Object
readonly
private
Returns the value of attribute interval.
-
#interval_condition ⇒ Object
readonly
private
Returns the value of attribute interval_condition.
-
#interval_type ⇒ Object
readonly
private
Returns the value of attribute interval_type.
Instance Method Summary collapse
- #filter_parameters ⇒ Object private
-
#initialize(allowed_attributes, condition_hash) ⇒ DateParamBuilder
constructor
A new instance of DateParamBuilder.
- #param_content ⇒ Object
- #validate_condition(condition) ⇒ Object private
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_attributes ⇒ Object (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 |
#attribute ⇒ Object (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 |
#interval ⇒ Object (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_condition ⇒ Object (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_type ⇒ Object (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_parameters ⇒ Object (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_content ⇒ Object
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 |