Sha256: 04a56715667523a7bef2e97a9625ea7f4bfd02829be0ca6b6fa009d4cb71ecd3

Contents?: true

Size: 650 Bytes

Versions: 9

Compression:

Stored size: 650 Bytes

Contents

require 'cassanity/increment'
require 'cassanity/decrement'

module Cassanity
  module ArgumentGenerators
    class SetClause

      # Internal
      def call(args = {})
        set = args.fetch(:set)
        cql, variables, sets = '', [], []

        set.each do |key, value|
          case value
          when Cassanity::Increment, Cassanity::Decrement
            sets << "#{key} = #{key} #{value.symbol} ?"
            variables << value.value
          else
            sets << "#{key} = ?"
            variables << value
          end
        end
        cql << " SET #{sets.join(', ')}"

        [cql, *variables]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cassanity-0.6.0.beta5 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.6.0.beta4 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.6.0.beta3 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.6.0.beta2 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.6.0.beta1 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.5.1 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.5.0 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.4.0 lib/cassanity/argument_generators/set_clause.rb
cassanity-0.3.0 lib/cassanity/argument_generators/set_clause.rb