Sha256: d0ad06536016f56546a3fa794a78a7925f327b2fac19b9d4cee5f4c7182f1009

Contents?: true

Size: 878 Bytes

Versions: 5

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module Dynamoid
  module Criteria
    # @private
    class IgnoredConditionsDetector
      def initialize(conditions)
        @conditions = conditions
        @ignored_keys = ignored_keys
      end

      def found?
        @ignored_keys.present?
      end

      def warning_message
        return unless found?

        'Where conditions may contain only one condition for an attribute. ' \
          "Following conditions are ignored: #{ignored_conditions}"
      end

      private

      def ignored_keys
        @conditions.keys
          .group_by(&method(:key_to_field))
          .select { |_, ary| ary.size > 1 }
          .flat_map { |_, ary| ary[0..-2] }
      end

      def key_to_field(key)
        key.to_s.split('.')[0]
      end

      def ignored_conditions
        @conditions.slice(*@ignored_keys)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynamoid-3.9.0 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.8.0 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.7.1 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.7.0 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.6.0 lib/dynamoid/criteria/ignored_conditions_detector.rb