Sha256: ab895ba9bf520b55882e540db2b6f7a7dadff833fe1988875ff2b9bbdf67cc11

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

require 'cassanity/argument_generators/with_clause'

module Cassanity
  module ArgumentGenerators
    class ColumnFamilyAlter

      # Internal
      def initialize(args = {})
        @with_clause = args.fetch(:with_clause) { WithClause.new }
      end

      # Internal
      def call(args = {})
        name = args.fetch(:column_family_name)
        with = args[:with] || {}

        variables = []

        if (keyspace_name = args[:keyspace_name])
          name = "#{keyspace_name}.#{name}"
        end

        cql = "ALTER COLUMNFAMILY #{name}"

        if (alter = args[:alter])
          column_name, column_type = alter.keys.first, alter.values.first
          cql << " ALTER #{column_name} TYPE #{column_type}"
        end

        if (add = args[:add])
          column_name, column_type = add.keys.first, add.values.first
          cql << " ADD #{column_name} #{column_type}"
        end

        if (column_name = args[:drop])
          cql << " DROP #{column_name}"
        end

        with_cql, *with_variables = @with_clause.call(with: with)
        cql << with_cql
        variables.concat(with_variables)

        [cql, *variables]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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