Class: Cassandra::Keyspace
- Inherits:
-
Object
- Object
- Cassandra::Keyspace
- Defined in:
- lib/cassandra/keyspace.rb
Overview
Represents a cassandra keyspace
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
This keyspace name.
Instance Method Summary collapse
-
#durable_writes? ⇒ Boolean
Whether durables writes are enabled for this keyspace.
-
#each_table(&block) ⇒ Object
(also: #tables)
Yield or enumerate each table defined in this keyspace.
-
#each_type(&block) ⇒ Object
(also: #types)
Yield or enumerate each user-defined type present in this keyspace.
-
#eql?(other) ⇒ Boolean
(also: #==)
Whether this keyspace is equal to the other.
-
#has_table?(name) ⇒ Boolean
Whether this keyspace has a table with the given name.
-
#has_type?(name) ⇒ Boolean
Whether this keyspace has a user-defined type with the given name.
-
#inspect ⇒ String
A CLI-friendly keyspace representation.
-
#table(name) ⇒ Cassandra::Table?
A table or nil.
-
#to_cql ⇒ String
A cql representation of this table.
-
#type(name) ⇒ Cassandra::Types::UserDefined?
A type or nil.
Instance Attribute Details
#name ⇒ String (readonly)
Returns 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.
63 64 65 |
# File 'lib/cassandra/keyspace.rb', line 63 def durable_writes? @durable_writes end |
#each_table {|table| ... } ⇒ Cassandra::Keyspace #each_table ⇒ Array<Cassandra::Table> Also known as: tables
Yield or enumerate each table defined in this keyspace
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_type ⇒ Array<Cassandra::Types::UserDefined> Also known as: types
Yield or enumerate each user-defined type present in this keyspace
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.
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.
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.
98 99 100 |
# File 'lib/cassandra/keyspace.rb', line 98 def has_type?(name) @types.has_key?(name) end |
#inspect ⇒ String
Returns 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.
75 76 77 |
# File 'lib/cassandra/keyspace.rb', line 75 def table(name) @tables[name] end |
#to_cql ⇒ String
Returns 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.
104 105 106 |
# File 'lib/cassandra/keyspace.rb', line 104 def type(name) @types[name] end |