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)



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_aggregateArray<Cassandra::Aggregate> Also known as: aggregates

Yield or enumerate each aggregate defined in this keyspace

Overloads:



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_functionArray<Cassandra::Function> Also known as: functions

Yield or enumerate each function defined in this keyspace

Overloads:



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_indexArray<Cassandra::Index> Also known as: indexes

Yield or enumerate each index defined in this keyspace

Overloads:



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_viewArray<Cassandra::MaterializedView> Also known as: materialized_views

Yield or enumerate each materialized view defined in this keyspace

Overloads:



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_tableArray<Cassandra::Table> Also known as: tables

Yield or enumerate each table defined in this keyspace

Overloads:



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_typeArray<Cassandra::Types::UserDefined> Also known as: types

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

Overloads:



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_cqlString



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