Sha256: 29b694bd29e4ca5eddd4364ef5cac3e866ca5ffbe1867ce06d7a2afeccc2b356

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module DynamoidAdvancedWhere
  module Nodes
    class AndNode < BaseNode
      include Concerns::Negatable
      attr_accessor :child_nodes

      def initialize(*child_nodes)
        self.child_nodes = child_nodes.freeze
        freeze
      end

      def to_expression
        return if child_nodes.empty?

        "(#{child_nodes.map(&:to_expression).join(') and (')})"
      end

      def expression_attribute_names
        child_nodes.map(&:expression_attribute_names).inject({}, &:merge!)
      end

      def expression_attribute_values
        child_nodes.map(&:expression_attribute_values).inject({}, &:merge!)
      end

      def and(other_value)
        AndNode.new(other_value, *child_nodes)
      end
      alias & and
    end

    module Concerns
      module SupportsLogicalAnd
        def and(other_value)
          AndNode.new(self, other_value)
        end
        alias & and
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
dynamoid_advanced_where-1.0.0 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid-advanced-where-1.0.0 lib/dynamoid_advanced_where/nodes/and_node.rb