Sha256: ec33f4183aba13d685b6ae18eb44bfd02cce5478292a0b6c44d8ed53313edf6f

Contents?: true

Size: 917 Bytes

Versions: 6

Compression:

Stored size: 917 Bytes

Contents

module DynamoidAdvancedWhere
  module Nodes
    class OrNode < 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(') or (')})"
      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 or(other_value)
        OrNode.new(other_value, *child_nodes)
      end
      alias | or
    end

    module Concerns
      module SupportsLogicalOr
        def or(other_value)
          OrNode.new(self, other_value)
        end
        alias | or
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dynamoid_advanced_where-1.3.0 lib/dynamoid_advanced_where/nodes/or_node.rb
dynamoid_advanced_where-1.2.0 lib/dynamoid_advanced_where/nodes/or_node.rb
dynamoid_advanced_where-1.1.0 lib/dynamoid_advanced_where/nodes/or_node.rb
dynamoid_advanced_where-1.0.1 lib/dynamoid_advanced_where/nodes/or_node.rb
dynamoid_advanced_where-1.0.0 lib/dynamoid_advanced_where/nodes/or_node.rb
dynamoid-advanced-where-1.0.0 lib/dynamoid_advanced_where/nodes/or_node.rb