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
-
#aggregate(name, *args) ⇒ Cassandra::Aggregate?
An aggregate or nil.
-
#durable_writes? ⇒ Boolean
Whether durables writes are enabled for this keyspace.
-
#each_aggregate(&block) ⇒ Object
(also: #aggregates)
Yield or enumerate each aggregate defined in this keyspace.
-
#each_function(&block) ⇒ Object
(also: #functions)
Yield or enumerate each function defined in this keyspace.
-
#each_index(&block) ⇒ Object
(also: #indexes)
Yield or enumerate each index defined in this keyspace.
-
#each_materialized_view(&block) ⇒ Object
(also: #materialized_views)
Yield or enumerate each materialized view defined in 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.
-
#function(name, *args) ⇒ Cassandra::Function?
A function or nil.
-
#has_aggregate?(name, *args) ⇒ Boolean
Whether this keyspace has an aggregate with the given name and arguments.
-
#has_function?(name, *args) ⇒ Boolean
Whether this keyspace has a function with the given name and arguments.
-
#has_index?(name) ⇒ Boolean
Whether this keyspace has an index with the given name.
-
#has_materialized_view?(name) ⇒ Boolean
Whether this keyspace has a materialized view with the given name.
-
#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.
-
#index(name) ⇒ Cassandra::Index?
An index or nil.
-
#materialized_view(name) ⇒ Cassandra::MaterializedView?
A materialized view or nil.
-
#table(name) ⇒ Cassandra::Table?
A table or nil.
-
#to_cql ⇒ String
A cql representation of this keyspace.
-
#type(name) ⇒ Cassandra::Types::UserDefined?
A type or nil.
Instance Attribute Details
#name ⇒ String (readonly)
49 50 51 |
# File 'lib/cassandra/keyspace.rb', line 49 def name @name end |
Instance Method Details
#aggregate(name, *args) ⇒ Cassandra::Aggregate?
257 258 259 |
# File 'lib/cassandra/keyspace.rb', line 257 def aggregate(name, *args) @aggregates.get(name.downcase, args) end |
#durable_writes? ⇒ Boolean
88 89 90 |
# File 'lib/cassandra/keyspace.rb', line 88 def durable_writes? @durable_writes end |
#each_aggregate {|aggregate| ... } ⇒ Cassandra::Keyspace #each_aggregate ⇒ Array<Cassandra::Aggregate> Also known as: aggregates
Yield or enumerate each aggregate defined in this keyspace
267 268 269 270 271 272 273 274 |
# File 'lib/cassandra/keyspace.rb', line 267 def each_aggregate(&block) if block_given? @aggregates.each_function(&block) self else @aggregates.functions end end |
#each_function {|function| ... } ⇒ Cassandra::Keyspace #each_function ⇒ Array<Cassandra::Function> Also known as: functions
Yield or enumerate each function defined in this keyspace
236 237 238 239 240 241 242 243 |
# File 'lib/cassandra/keyspace.rb', line 236 def each_function(&block) if block_given? @functions.each_function(&block) self else @functions.functions end end |
#each_index {|index| ... } ⇒ Cassandra::Keyspace #each_index ⇒ Array<Cassandra::Index> Also known as: indexes
Yield or enumerate each index defined in this keyspace
138 139 140 141 142 143 144 145 |
# File 'lib/cassandra/keyspace.rb', line 138 def each_index(&block) if block_given? @indexes_hash.each_value(&block) self else @indexes_hash.values end end |
#each_materialized_view {|view| ... } ⇒ Cassandra::Keyspace #each_materialized_view ⇒ Array<Cassandra::MaterializedView> Also known as: materialized_views
Yield or enumerate each materialized view defined in this keyspace
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cassandra/keyspace.rb', line 168 def each_materialized_view(&block) if block_given? @views.each_value do |v| yield(v) if v.base_table end self else result = [] @views.each_value do |v| result << v if v.base_table end result end end |
#each_table {|table| ... } ⇒ Cassandra::Keyspace #each_table ⇒ Array<Cassandra::Table> Also known as: tables
Yield or enumerate each table defined in this keyspace
110 111 112 113 114 115 116 117 |
# File 'lib/cassandra/keyspace.rb', line 110 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
203 204 205 206 207 208 209 210 |
# File 'lib/cassandra/keyspace.rb', line 203 def each_type(&block) if block_given? @types.each_value(&block) self else @types.values end end |
#function(name, *args) ⇒ Cassandra::Function?
224 225 226 227 228 |
# File 'lib/cassandra/keyspace.rb', line 224 def function(name, *args) # The functions_hash datastructure is a hash <[func-name, args], Function>. # So construct the array-key we're looking for. @functions.get(name.downcase, args) end |
#has_aggregate?(name, *args) ⇒ Boolean
250 251 252 |
# File 'lib/cassandra/keyspace.rb', line 250 def has_aggregate?(name, *args) !@aggregates.get(name.downcase, args).nil? end |
#has_function?(name, *args) ⇒ Boolean
217 218 219 |
# File 'lib/cassandra/keyspace.rb', line 217 def has_function?(name, *args) !@functions.get(name.downcase, args).nil? end |
#has_index?(name) ⇒ Boolean
122 123 124 |
# File 'lib/cassandra/keyspace.rb', line 122 def has_index?(name) @indexes_hash.key?(name) end |
#has_materialized_view?(name) ⇒ Boolean
150 151 152 153 154 |
# File 'lib/cassandra/keyspace.rb', line 150 def has_materialized_view?(name) # We check if the view exists *and* that its base-table is set. If base-table isn't available, # it will be soon, so the user can poll on this method until we return a fully-baked materialized view. @views.key?(name) && !@views[name].base_table.nil? end |
#has_table?(name) ⇒ Boolean
94 95 96 |
# File 'lib/cassandra/keyspace.rb', line 94 def has_table?(name) @tables.key?(name) end |
#has_type?(name) ⇒ Boolean
187 188 189 |
# File 'lib/cassandra/keyspace.rb', line 187 def has_type?(name) @types.key?(name) end |
#index(name) ⇒ Cassandra::Index?
128 129 130 |
# File 'lib/cassandra/keyspace.rb', line 128 def index(name) @indexes_hash[name] end |
#materialized_view(name) ⇒ Cassandra::MaterializedView?
158 159 160 |
# File 'lib/cassandra/keyspace.rb', line 158 def materialized_view(name) @views[name] if has_materialized_view?(name) end |
#table(name) ⇒ Cassandra::Table?
100 101 102 |
# File 'lib/cassandra/keyspace.rb', line 100 def table(name) @tables[name] end |
#to_cql ⇒ String
278 279 280 281 282 |
# File 'lib/cassandra/keyspace.rb', line 278 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?
193 194 195 |
# File 'lib/cassandra/keyspace.rb', line 193 def type(name) @types[name] end |