Sha256: 29ba4686b16d13cb087d062bdc59b4cd5c3455fc126a8a2ebad48292352bf434

Contents?: true

Size: 1.4 KB

Versions: 20

Compression:

Stored size: 1.4 KB

Contents

module CassandraObject
  module Tasks
    class ColumnFamily
      COLUMN_TYPES = {
        standard: 'Standard',
        super:    'Super'
      }

      def initialize(keyspace)
        @keyspace = keyspace
      end

      def exists?(name)
        connection.schema.cf_defs.find { |cf_def| cf_def.name == name.to_s }
      end

      def create(name)
        cf = Cassandra::ColumnFamily.new
        cf.name = name.to_s
        cf.keyspace = @keyspace.to_s
        cf.comparator_type = 'UTF8Type'
        cf.column_type = 'Standard'

        yield(cf) if block_given?

        post_process_column_family(cf)
        connection.add_column_family(cf)
      end

      def drop(name)
        connection.drop_column_family(name.to_s)
      end

      def rename(old_name, new_name)
        connection.rename_column_family(old_name.to_s, new_name.to_s)
      end

      private
        def connection
          CassandraObject::Base.connection
        end

        def post_process_column_family(cf)
          col_type = cf.column_type
          if col_type && COLUMN_TYPES.has_key?(col_type)
            cf.column_type = COLUMN_TYPES[col_type]
          end

          cf
        end
    end
  end
end

class Cassandra
  class ColumnFamily
    def with_fields(options)
      struct_fields.collect { |f| f[1][:name] }.each do |f|
        send("#{f}=", options[f.to_sym] || options[f.to_s])
      end
      self
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gotime-cassandra_object-3.0.2 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-3.0.1 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-3.0.0 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.13.0 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.5 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.4 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.3 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.2 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.1 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.12.0 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.9 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.8 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.7 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.6 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.5 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.4 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.3 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.2 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.1 lib/cassandra_object/tasks/column_family.rb
gotime-cassandra_object-2.11.0 lib/cassandra_object/tasks/column_family.rb