Class: Cassanity::ArgumentGenerators::ColumnFamilyAlter

Inherits:
Object
  • Object
show all
Defined in:
lib/cassanity/argument_generators/column_family_alter.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ColumnFamilyAlter

Internal

[View source]

8
9
10
# File 'lib/cassanity/argument_generators/column_family_alter.rb', line 8

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

Instance Method Details

#call(args = {}) ⇒ Object

Internal

[View source]

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cassanity/argument_generators/column_family_alter.rb', line 13

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