Skip to content
Browse files

Rejigger adapter-redis into adapter-cassandra.

Big ups to Nunemaker for getting me the adapter we wrote at RubyConf and for starting this ball rolling.
  • Loading branch information...
0 parents commit 60b8ee1cdee94d490970b52cb3464bd36f43dae0 @therealadam committed
Showing with 237 additions and 0 deletions.
  1. 0 .rspec
  2. +17 −0 Gemfile
  3. +52 −0 Gemfile.lock
  4. +19 −0 LICENSE
  5. +13 −0 README.rdoc
  6. +7 −0 Rakefile
  7. +22 −0 adapter-cassandra.gemspec
  8. +26 −0 examples/cassandra.rb
  9. +34 −0 lib/adapter/cassandra.rb
  10. +5 −0 lib/adapter/cassandra/version.rb
  11. +1 −0 log/test.log
  12. +16 −0 spec/cassandra_spec.rb
  13. +25 −0 spec/helper.rb
0 .rspec
No changes.
17 Gemfile
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in adapter-cassandra.gemspec
+gemspec
+
+group(:development) do
+ gem 'rspec', '~> 2.3'
+ gem 'log_buddy', '~> 0.5.0'
+ gem 'timecop', '~> 0.3.5'
+ gem 'SystemTimer', '~> 1.2.1'
+ gem 'i18n', '0.5.0'
+ gem 'activesupport', '~> 3', :require => 'active_support'
+
+ # Requiring like this is totally ghetto
+ gem 'adapter', :path => '~/Desktop/Do/adapter'
+ gem 'cassandra', '~> 0.9.0', :require => 'cassandra/0.7'
+end
52 Gemfile.lock
@@ -0,0 +1,52 @@
+PATH
+ remote: .
+ specs:
+ adapter-cassandra (0.5.1)
+
+PATH
+ remote: ~/Desktop/Do/adapter
+ specs:
+ adapter (0.5.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ SystemTimer (1.2.1)
+ activesupport (3.0.3)
+ cassandra (0.9.0)
+ json
+ rake
+ simple_uuid (>= 0.1.0)
+ thrift_client (>= 0.6.0)
+ diff-lcs (1.1.2)
+ i18n (0.5.0)
+ json (1.4.6)
+ log_buddy (0.5.0)
+ rake (0.8.7)
+ rspec (2.4.0)
+ rspec-core (~> 2.4.0)
+ rspec-expectations (~> 2.4.0)
+ rspec-mocks (~> 2.4.0)
+ rspec-core (2.4.0)
+ rspec-expectations (2.4.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.4.0)
+ simple_uuid (0.1.1)
+ thrift (0.5.0)
+ thrift_client (0.6.0)
+ thrift (~> 0.5.0)
+ timecop (0.3.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ SystemTimer (~> 1.2.1)
+ activesupport (~> 3)
+ adapter!
+ adapter-cassandra!
+ cassandra (~> 0.9.0)
+ i18n (= 0.5.0)
+ log_buddy (~> 0.5.0)
+ rspec (~> 2.3)
+ timecop (~> 0.3.5)
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Adam Keys
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
13 README.rdoc
@@ -0,0 +1,13 @@
+= adapter-cassandra
+
+Cassandra adapter for adapter gem.
+
+See examples/ or specs/ for usage.
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so we don't break it in a future version unintentionally.
+* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
+* Send us a pull request. Bonus points for topic branches.
7 Rakefile
@@ -0,0 +1,7 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new
+
+task :default => :spec
22 adapter-cassandra.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "adapter/cassandra/version"
+
+Gem::Specification.new do |s|
+ s.name = "adapter-cassandra"
+ s.version = Adapter::Cassandra::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Adam Keys"]
+ s.email = ["adam@therealadam.com"]
+ s.homepage = ""
+ s.summary = %q{Adapter for cassandra}
+ s.description = %q{Adapter for cassandra}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # s.add_dependency 'adapter', '~> 0.5.1'
+ # s.add_dependency 'cassandra', '~> 0.9.0'
+end
26 examples/cassandra.rb
@@ -0,0 +1,26 @@
+require 'rubygems'
+require 'pathname'
+
+root_path = Pathname(__FILE__).dirname.join('..').expand_path
+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.clear
+
+adapter.write('foo', 'bar')
+puts 'Should be bar: ' + adapter.read('foo').inspect
+
+adapter.delete('foo')
+puts 'Should be nil: ' + adapter.read('foo').inspect
+
+adapter.write('foo', 'bar')
+adapter.clear
+puts 'Should be nil: ' + adapter.read('foo').inspect
+
+puts 'Should be bar: ' + adapter.fetch('foo', 'bar')
+puts 'Should be bar: ' + adapter.read('foo')
34 lib/adapter/cassandra.rb
@@ -0,0 +1,34 @@
+require 'adapter'
+# require 'cassandra/0.7'
+
+module Adapter
+ module Cassandra
+ def read(key)
+ decode(client.get(options[:column_family], key_for(key)))
+ end
+
+ def write(key, value)
+ client.insert(options[:column_family], key_for(key), encode(value))
+ end
+
+ def delete(key)
+ read(key).tap { client.remove(options[:column_family], key_for(key)) }
+ end
+
+ def clear
+ client.clear_keyspace!
+ end
+
+ def encode(value)
+ {'toystore' => Marshal.dump(value)}
+ end
+
+ def decode(value)
+ return nil if value.empty?
+ Marshal.load(value['toystore'])
+ end
+ end
+end
+
+Adapter.define(:cassandra, Adapter::Cassandra)
+
5 lib/adapter/cassandra/version.rb
@@ -0,0 +1,5 @@
+module Adapter
+ module Cassandra
+ VERSION = "0.5.1"
+ end
+end
1 log/test.log
@@ -0,0 +1 @@
+# Logfile created on Wed Jan 26 19:41:53 -0600 2011 by logger.rb
16 spec/cassandra_spec.rb
@@ -0,0 +1,16 @@
+require 'helper'
+require 'adapter/cassandra'
+
+describe "Cassandra adapter" do
+ before do
+ @client = Cassandra.new("Toystore")
+ @adapter = Adapter[:cassandra].new(@client, :column_family => :boom)
+ @adapter.clear
+ end
+
+ let(:adapter) { @adapter }
+ let(:client) { @client }
+
+ it_should_behave_like 'a marshaled adapter'
+
+end
25 spec/helper.rb
@@ -0,0 +1,25 @@
+$:.unshift(File.expand_path('../../lib', __FILE__))
+
+require 'rubygems'
+require 'bundler'
+
+Bundler.require(:default, :development)
+
+require 'pathname'
+require 'logger'
+
+root_path = Pathname(__FILE__).dirname.join('..').expand_path
+lib_path = root_path.join('lib')
+log_path = root_path.join('log')
+log_path.mkpath
+
+require 'adapter/spec/an_adapter'
+require 'adapter/spec/marshal_adapter'
+require 'adapter/spec/json_adapter'
+require 'adapter/spec/types'
+
+logger = Logger.new(log_path.join('test.log'))
+LogBuddy.init(:logger => logger)
+
+Rspec.configure do |c|
+end

0 comments on commit 60b8ee1

Please sign in to comment.
Something went wrong with that request. Please try again.