Sha256: 95aea844662bebff5384bb56cb819d4df6767d83851e1d622edff9e31683d6a0

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

module Dynamoid
  module Criteria
    class NonexistentFieldsDetector
      def initialize(conditions, source)
        @conditions = conditions
        @source = source
        @nonexistent_fields = nonexistent_fields
      end

      def found?
        @nonexistent_fields.present?
      end

      def warning_message
        return unless found?

        fields_list = @nonexistent_fields.map { |s| "`#{s}`" }.join(', ')
        count = @nonexistent_fields.size

        "where conditions contain nonexistent" \
          " field #{ 'name'.pluralize(count) } #{ fields_list }"
      end

      private

      def nonexistent_fields
        fields_from_conditions - fields_existent
      end

      def fields_from_conditions
        @conditions.keys.map { |s| s.to_s.split('.')[0].to_sym }
      end

      def fields_existent
        @source.attributes.keys.map(&:to_sym)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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