Sha256: 82cc228ba8756d43953f2dc959dbdf36fc1ea4b4adaeae293ff53fa29ee9d0eb

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

require_relative 'base_conditions_filter'

module Gitlab
  module Triage
    module Filters
      class DateConditionsFilter < BaseConditionsFilter
        ATTRIBUTES = %w[updated_at created_at].freeze
        CONDITIONS = %w[older_than newer_than].freeze
        INTERVAL_TYPES = %w[days weeks months years].freeze

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

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

        def resource_value
          @resource[@attribute].to_date
        end

        def condition_value
          @interval.public_send(@interval_type).ago.to_date # rubocop:disable GitlabSecurity/PublicSend
        end

        def calculate
          case @condition
          when :older_than
            resource_value < condition_value
          when :newer_than
            resource_value > condition_value
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
gitlab-triage-1.4.2 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.4.1 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.4.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.3.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.2.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.1.1 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.1.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.0.1 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-1.0.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.17.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.16.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.15.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.14.1 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.14.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.13.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.12.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.11.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.10.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.9.0 lib/gitlab/triage/filters/date_conditions_filter.rb
gitlab-triage-0.8.1 lib/gitlab/triage/filters/date_conditions_filter.rb