Class: Cassandra::Keyspace

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra/keyspace.rb

Overview

Represents a cassandra keyspace

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString (readonly)

Returns this keyspace name.

Returns:

  • (String)

    this keyspace name



49
50
51
# File 'lib/cassandra/keyspace.rb', line 49

def name
  @name
end

Instance Method Details

#durable_writes?Boolean

Returns whether durables writes are enabled for this keyspace.

Returns:

  • (Boolean)

    whether durables writes are enabled for this keyspace



63
64
65
# File 'lib/cassandra/keyspace.rb', line 63

def durable_writes?
  @durable_writes
end

#each_table {|table| ... } ⇒ Cassandra::Keyspace #each_tableArray<Cassandra::Table> Also known as: tables

Yield or enumerate each table defined in this keyspace

Overloads:



85
86
87
88
89
90
91
92
# File 'lib/cassandra/keyspace.rb', line 85

def each_table(&block)
  if block_given?
    @tables.each_value(&block)
    self
  else
    @tables.values
  end
end

#each_type {|type| ... } ⇒ Cassandra::Keyspace #each_typeArray<Cassandra::Types::UserDefined> Also known as: types

Yield or enumerate each user-defined type present in this keyspace

Overloads:



114
115
116
117
118
119
120
121
# File 'lib/cassandra/keyspace.rb', line 114

def each_type(&block)
  if block_given?
    @types.each_value(&block)
    self
  else
    @types.values
  end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns whether this keyspace is equal to the other.

Returns:

  • (Boolean)

    whether this keyspace is equal to the other



130
131
132
133
134
135
136
137
# File 'lib/cassandra/keyspace.rb', line 130

def eql?(other)
  other.is_a?(Keyspace) &&
    @name == other.name &&
    @durable_writes == other.durable_writes &&
    @replication == other.replication &&
    @tables == other.raw_tables &&
    @types == other.raw_types
end

#has_table?(name) ⇒ Boolean

Returns whether this keyspace has a table with the given name.

Parameters:

  • name (String)

    table name

Returns:

  • (Boolean)

    whether this keyspace has a table with the given name



69
70
71
# File 'lib/cassandra/keyspace.rb', line 69

def has_table?(name)
  @tables.has_key?(name)
end

#has_type?(name) ⇒ Boolean

Returns whether this keyspace has a user-defined type with the given name.

Parameters:

  • name (String)

    user-defined type name

Returns:

  • (Boolean)

    whether this keyspace has a user-defined type with the given name



98
99
100
# File 'lib/cassandra/keyspace.rb', line 98

def has_type?(name)
  @types.has_key?(name)
end

#inspectString

Returns a CLI-friendly keyspace representation.

Returns:

  • (String)

    a CLI-friendly keyspace representation



141
142
143
# File 'lib/cassandra/keyspace.rb', line 141

def inspect
  "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @name=#{@name}>"
end

#table(name) ⇒ Cassandra::Table?

Returns a table or nil.

Parameters:

  • name (String)

    table name

Returns:



75
76
77
# File 'lib/cassandra/keyspace.rb', line 75

def table(name)
  @tables[name]
end

#to_cqlString

Returns a cql representation of this table.

Returns:

  • (String)

    a cql representation of this table



125
126
127
# File 'lib/cassandra/keyspace.rb', line 125

def to_cql
  "CREATE KEYSPACE #{Util.escape_name(@name)} WITH REPLICATION = #{@replication.to_cql} AND DURABLE_WRITES = #{@durable_writes};"
end

#type(name) ⇒ Cassandra::Types::UserDefined?

Returns a type or nil.

Parameters:

  • name (String)

    user-defined type name

Returns:



104
105
106
# File 'lib/cassandra/keyspace.rb', line 104

def type(name)
  @types[name]
end