Sha256: 8043e9ed5fce7c10e23f45234cc1fc3d41fb6ae837f2ff1f8a91e388a82124ad

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

class Dynomite::Item::Query::Params
  class Base
    extend Memoist
    include Dynomite::Types
    include Helpers

    # To add function example:
    # 1. params/base.rb function_names
    # 2. query/chain.rb: add method
    # 3. params/function/begins_with.rb: filter_expression, attribute_names, attribute_values
    def function_names
      %w[attribute_exists attribute_type begins_with contains size_fn]
    end

    def join_expressions
      joined = ''
      @expressions.each do |expression|
        string = expression_string(expression)
        if joined.empty? # first pass
          joined << string
        else
          if !expression.is_a?(String) && expression.or?
            joined << " OR #{string}"
          else
            joined << " AND #{string}"
          end
        end
      end
      joined
    end

    def expression_string(expression)
      if expression.is_a?(String)
        # Function filter expression is simple String
        expression
      else
        # Else expression is CompressionExpression object with extra info like .or?
        expression.build  # build the string
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynomite-2.0.3 lib/dynomite/item/query/params/base.rb
dynomite-2.0.2 lib/dynomite/item/query/params/base.rb
dynomite-2.0.1 lib/dynomite/item/query/params/base.rb
dynomite-2.0.0 lib/dynomite/item/query/params/base.rb