Sha256: e2afca506c3bf73f62c241556baacba5a60e367084ada0beb8900d8e496ee851

Contents?: true

Size: 874 Bytes

Versions: 4

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

module Dynamoid
  module Criteria
    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 { |field, ary| ary.size > 1 }
          .flat_map { |field, 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

4 entries across 4 versions & 1 rubygems

Version Path
dynamoid-3.4.1 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.4.0 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.3.0 lib/dynamoid/criteria/ignored_conditions_detector.rb
dynamoid-3.2.0 lib/dynamoid/criteria/ignored_conditions_detector.rb