Class: Cassanity::ArgumentGenerators::KeyspaceCreate

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ KeyspaceCreate

Returns a new instance of KeyspaceCreate.



7
8
9
# File 'lib/cassanity/argument_generators/keyspace_create.rb', line 7

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

Instance Method Details

#call(args = {}) ⇒ Object

Internal



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cassanity/argument_generators/keyspace_create.rb', line 12

def call(args = {})
  options, variables = [], []
  name = args.fetch(:keyspace_name)
  cql = "CREATE KEYSPACE #{name}"

  replication = args.fetch(:replication, {})

  if replication.empty? || replication[:class] !~ /NetworkTopologyStrategy/
    replication = default_replication_options.merge(replication)
  end

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

  [cql, *variables]
end

#default_replication_optionsObject

Private



31
32
33
34
35
36
# File 'lib/cassanity/argument_generators/keyspace_create.rb', line 31

def default_replication_options
  {
    class: 'SimpleStrategy',
    replication_factor: 1,
  }
end