Permalink
Browse files

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

  • Loading branch information...
1 parent f33e8b2 commit 15770d305fd0864df4e969cccc0dd0033b44c662 @therealadam committed Feb 15, 2011
Showing with 17 additions and 7 deletions.
  1. +1 −2 examples/cassandra.rb
  2. +13 −3 lib/adapter/cassandra.rb
  3. +3 −2 spec/cassandra_spec.rb
View
@@ -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
@@ -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
@@ -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

0 comments on commit 15770d3

Please sign in to comment.