Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store in columns if possible. It's the right thing to do.

  • Loading branch information...
commit 15770d305fd0864df4e969cccc0dd0033b44c662 1 parent f33e8b2
@therealadam authored
View
3  examples/cassandra.rb
@@ -5,11 +5,10 @@
lib_path = root_path.join('lib')
$:.unshift(lib_path)
-require 'cassandra/0.7'
require 'adapter/cassandra'
client = Cassandra.new('Toystore')
-adapter = Adapter[:cassandra].new(client, :column_family => :boom)
+adapter = Adapter[:cassandra].new(client, :column_family => :Boom)
adapter.clear
adapter.write('foo', 'bar')
View
16 lib/adapter/cassandra.rb
@@ -1,5 +1,5 @@
require 'adapter'
-# require 'cassandra/0.7'
+require 'cassandra/0.7'
module Adapter
module Cassandra
@@ -20,12 +20,22 @@ def clear
end
def encode(value)
- {'toystore' => Marshal.dump(value)}
+ case value
+ when String
+ {"toystore" => value}
+ when Hash
+ value.inject({}) { |result, (k, v)| result.update(k.to_s => v.to_s) }
+ end
end
def decode(value)
return nil if value.empty?
- Marshal.load(value['toystore'])
+ case value
+ when Hash
+ value["toystore"] if value.has_key?("toystore")
+ else
+ value
+ end
end
end
end
View
5 spec/cassandra_spec.rb
@@ -2,15 +2,16 @@
require 'adapter/cassandra'
describe "Cassandra adapter" do
+
before do
@client = Cassandra.new("Toystore")
- @adapter = Adapter[:cassandra].new(@client, :column_family => :boom)
+ @adapter = Adapter[:cassandra].new(@client, :column_family => :Boom)
@adapter.clear
end
let(:adapter) { @adapter }
let(:client) { @client }
- it_should_behave_like 'a marshaled adapter'
+ it_behaves_like "an adapter"
end
Please sign in to comment.
Something went wrong with that request. Please try again.