Sha256: 64c7e1805c76d42d13ef88e5df6dcef21a052c27a0fd362db7520467362b1b7d

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

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

    # I know this is weird but it prevents a circular dependency
    require_relative './not'

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dynamoid_advanced_where-1.8.0 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.7.1 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.7.0 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.6.0 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.5.1 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.5.0 lib/dynamoid_advanced_where/nodes/and_node.rb
dynamoid_advanced_where-1.4.0 lib/dynamoid_advanced_where/nodes/and_node.rb