Permalink
Browse files

Initial commit. Uses hacky value key for stuff.

Going to use straight up document next.
  • Loading branch information...
jnunemaker committed Feb 3, 2011
0 parents commit 98ea68c4e51bcbb932b1ad30b8ec00eed243f56d
Showing with 347 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +16 −0 Gemfile
  3. +64 −0 Gemfile.lock
  4. +20 −0 LICENSE
  5. +7 −0 Rakefile
  6. +22 −0 adapter-mongo.gemspec
  7. +25 −0 examples/mongo.rb
  8. +34 −0 lib/adapter/mongo.rb
  9. +5 −0 lib/adapter/mongo/version.rb
  10. +101 −0 log/test.log
  11. +35 −0 spec/helper.rb
  12. +15 −0 spec/mongo_spec.rb
@@ -0,0 +1,3 @@
pkg/*
*.gem
.bundle
16 Gemfile
@@ -0,0 +1,16 @@
source "http://rubygems.org"
# Specify your gem's dependencies in adapter-mongo.gemspec
gemspec
group(:development) do
gem 'rspec', '~> 2.3'
gem 'log_buddy', '~> 0.5.0'
gem 'timecop', '~> 0.3.5'
gem 'i18n', '0.5.0'
gem 'activesupport', '~> 3', :require => 'active_support'
gem 'bson_ext', '~> 1.2.0'
gem 'ruby-debug', :platform => :ruby_18
gem 'ruby-debug19', :platform => :ruby_19, :require => 'ruby-debug'
end
@@ -0,0 +1,64 @@
PATH
remote: .
specs:
adapter-mongo (0.5)
adapter (~> 0.5.1)
mongo (~> 1.2.0)
GEM
remote: http://rubygems.org/
specs:
activesupport (3.0.3)
adapter (0.5.2)
archive-tar-minitar (0.5.2)
bson (1.2.0)
bson_ext (1.2.0)
columnize (0.3.2)
diff-lcs (1.1.2)
i18n (0.5.0)
linecache (0.43)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
log_buddy (0.5.0)
mongo (1.2.0)
bson (>= 1.2.0)
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)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
timecop (0.3.5)
PLATFORMS
ruby
DEPENDENCIES
activesupport (~> 3)
adapter (~> 0.5.1)
adapter-mongo!
bson_ext (~> 1.2.0)
i18n (= 0.5.0)
log_buddy (~> 0.5.0)
mongo (~> 1.2.0)
rspec (~> 2.3)
ruby-debug
ruby-debug19
timecop (~> 0.3.5)
20 LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2011 John Nunemaker
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.
@@ -0,0 +1,7 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :default => :spec
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "adapter/mongo/version"
Gem::Specification.new do |s|
s.name = "adapter-mongo"
s.version = Adapter::Mongo::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["John Nunemaker"]
s.email = ["nunemaker@gmail.com"]
s.homepage = ""
s.summary = %q{Adapter for mongo}
s.description = %q{Adapter for mongo}
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 'mongo', '~> 1.2.0'
end
@@ -0,0 +1,25 @@
require 'rubygems'
require 'pathname'
root_path = Pathname(__FILE__).dirname.join('..').expand_path
lib_path = root_path.join('lib')
$:.unshift(lib_path)
require 'adapter/mongo'
client = Mongo::Connection.new.db('adapter')['testing']
adapter = Adapter[:mongo].new(client)
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')
@@ -0,0 +1,34 @@
require 'adapter'
require 'mongo'
module Adapter
module Mongo
def read(key)
if doc = client.find_one('_id' => key_for(key))
decode(doc)
end
end
def write(key, value)
client.save('_id' => key_for(key), 'value' => encode(value))
end
def delete(key)
read(key).tap { client.remove('_id' => key_for(key))}
end
def clear
client.remove
end
def encode(value)
value
end
def decode(value)
value && value['value']
end
end
end
Adapter.define(:mongo, Adapter::Mongo)
@@ -0,0 +1,5 @@
module Adapter
module Mongo
VERSION = "0.5"
end
end
@@ -0,0 +1,101 @@
# Logfile created on Thu Feb 03 09:08:05 -0500 2011 by logger.rb
D, [2011-02-03T09:10:58.204661 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.209325 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.211837 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.214308 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.216590 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.218848 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.221382 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.224140 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.226556 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.229142 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.231546 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.233860 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.236431 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.242707 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.245981 #18222] DEBUG -- : key = "key"
D, [2011-02-03T09:10:58.249845 #18222] DEBUG -- : key = #<struct #<Class:0x10108ca80> foo=:bar>
D, [2011-02-03T09:10:58.253667 #18222] DEBUG -- : key = #<struct #<Class:0x101084a60> foo=:bar>
D, [2011-02-03T09:10:58.263219 #18222] DEBUG -- : key = #<struct #<Class:0x101070ee8> foo=:bar>
D, [2011-02-03T09:10:58.266937 #18222] DEBUG -- : key = #<struct #<Class:0x101068ba8> foo=:bar>
D, [2011-02-03T09:11:55.657172 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.657825 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>{"foo"=>:bar}}
D, [2011-02-03T09:11:55.663921 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.666827 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.667326 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.670437 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.671005 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.673365 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.673866 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>{"foo"=>:bar}}
D, [2011-02-03T09:11:55.676317 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.679298 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.679806 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.682394 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.682914 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.685868 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.689148 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.690046 #18355] DEBUG -- : key = "key2"
D, [2011-02-03T09:11:55.693727 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.694439 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.697517 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.698093 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.700749 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.701243 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.703567 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.704074 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value2"}
D, [2011-02-03T09:11:55.708152 #18355] DEBUG -- : key = "key"
D, [2011-02-03T09:11:55.708842 #18355] DEBUG -- : doc = {"_id"=>"key", "value"=>"value"}
D, [2011-02-03T09:11:55.712637 #18355] DEBUG -- : key = #<struct #<Class:0x10103a5a0> foo=:bar>
D, [2011-02-03T09:11:55.716432 #18355] DEBUG -- : key = #<struct #<Class:0x101032f58> foo=:bar>
D, [2011-02-03T09:11:55.725740 #18355] DEBUG -- : key = #<struct #<Class:0x10101dec8> foo=:bar>
D, [2011-02-03T09:11:55.729651 #18355] DEBUG -- : key = #<struct #<Class:0x1010162b8> foo=:bar>
@@ -0,0 +1,35 @@
$:.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/types'
shared_examples_for "a mongo adapter" do
it_should_behave_like 'an adapter'
Adapter::Spec::Types.each do |type, (key, key2)|
it "writes Object values to keys that are #{type}s like a Hash" do
adapter[key] = {:foo => :bar}
adapter[key].should == {'foo' => :bar} # mongo can serialize symbol values
end
end
end
logger = Logger.new(log_path.join('test.log'))
LogBuddy.init(:logger => logger)
Rspec.configure do |c|
end
@@ -0,0 +1,15 @@
require 'helper'
require 'adapter/mongo'
describe "Mongo adapter" do
before do
@client = Mongo::Connection.new.db('adapter')['testing']
@adapter = Adapter[:mongo].new(@client)
@adapter.clear
end
let(:adapter) { @adapter }
let(:client) { @client }
it_should_behave_like 'a mongo adapter'
end

0 comments on commit 98ea68c

Please sign in to comment.