Class: Cassanity::ArgumentGenerators::ColumnFamilyCreate
- Inherits:
-
Object
- Object
- Cassanity::ArgumentGenerators::ColumnFamilyCreate
- Defined in:
- lib/cassanity/argument_generators/column_family_create.rb
Instance Method Summary collapse
-
#call(args = {}) ⇒ Object
Internal.
-
#initialize(args = {}) ⇒ ColumnFamilyCreate
constructor
Internal.
Constructor Details
#initialize(args = {}) ⇒ ColumnFamilyCreate
Internal
8 9 10 |
# File 'lib/cassanity/argument_generators/column_family_create.rb', line 8 def initialize(args = {}) @with_clause = args.fetch(:with_clause) { WithClause.new } end |
Instance Method Details
#call(args = {}) ⇒ Object
Internal
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 |
# File 'lib/cassanity/argument_generators/column_family_create.rb', line 13 def call(args = {}) name = args.fetch(:name) schema = args.fetch(:schema) columns = schema.columns primary_keys = schema.primary_keys with = schema.with definitions, variables = [], [] if (keyspace_name = args[:keyspace_name]) name = "#{keyspace_name}.#{name}" end columns.each do |name, type| definitions << "#{name} #{type}" end definitions << "PRIMARY KEY (#{primary_keys.join(', ')})" cql_definition = definitions.join(', ') cql = "CREATE COLUMNFAMILY #{name} (#{cql_definition})" with_cql, *with_variables = @with_clause.call(with: with) cql << with_cql variables.concat(with_variables) [cql, *variables] end |