Class: CurlyMustache::Adapters::Cassandra

Inherits:
Abstract
  • Object
show all
Defined in:
lib/curly_mustache/adapters/cassandra.rb

Instance Attribute Summary

Attributes inherited from Abstract

#model_class

Instance Method Summary collapse

Methods inherited from Abstract

#adapter_name, #lock, #locked?, #mget, #unlock

Constructor Details

#initialize(options) ⇒ Cassandra

Returns a new instance of Cassandra.



7
8
9
10
# File 'lib/curly_mustache/adapters/cassandra.rb', line 7

def initialize(options)
  @client = ::Cassandra.new(options[:keyspace], options[:servers])
  @column_family = options[:column_family]
end

Instance Method Details

#column_familyObject



12
13
14
# File 'lib/curly_mustache/adapters/cassandra.rb', line 12

def column_family
  @column_family || model_class.name.pluralize.to_sym
end

#delete(key) ⇒ Object



25
26
27
# File 'lib/curly_mustache/adapters/cassandra.rb', line 25

def delete(key)
  @client.remove(column_family, key)
end

#flush_dbObject



29
30
31
# File 'lib/curly_mustache/adapters/cassandra.rb', line 29

def flush_db
  @client.clear_keyspace!
end

#get(key) ⇒ Object



20
21
22
23
# File 'lib/curly_mustache/adapters/cassandra.rb', line 20

def get(key)
  result = @client.get(column_family, key)
  result.empty? ? nil : result
end

#put(key, value) ⇒ Object



16
17
18
# File 'lib/curly_mustache/adapters/cassandra.rb', line 16

def put(key, value)
  @client.insert(column_family, key, value)
end