Sha256: 630ba261b230943427f3c43722546558c0bc3434b7c8d498df0825f472258889
Contents?: true
Size: 1.88 KB
Versions: 11
Compression:
Stored size: 1.88 KB
Contents
require_relative '../validators/params_validator' module Gitlab module Triage module ParamBuilders class DateParamBuilder 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 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 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 private attr_reader :allowed_attributes, :attribute, :interval_condition, :interval_type, :interval def validate_condition(condition) ParamsValidator.new(filter_parameters, condition).validate! end 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 end end end end
Version data entries
11 entries across 11 versions & 2 rubygems