campchair 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -13
- data/campchair.gemspec +5 -4
- data/lib/campchair/model.rb +73 -0
- data/lib/campchair/{leveldb.rb → store.rb} +29 -9
- data/lib/campchair/version.rb +1 -1
- data/lib/campchair.rb +3 -2
- data/spec/campchair/model_spec.rb +95 -0
- data/spec/campchair/{leveldb_spec.rb → store_spec.rb} +65 -22
- data/spec/integration/readme_examples_spec.rb +15 -20
- data/spec/spec_helper.rb +6 -0
- metadata +35 -17
    
        data/README.md
    CHANGED
    
    | @@ -1,22 +1,24 @@ | |
| 1 1 | 
             
            # ⑁ Campchair
         | 
| 2 | 
            -
            ###  | 
| 2 | 
            +
            ### A fast, ghetto-tech CouchDB-like persistence layer for Ruby
         | 
| 3 3 |  | 
| 4 4 | 
             
            [](http://travis-ci.org/captainpete/campchair)
         | 
| 5 5 |  | 
| 6 6 | 
             
            ___This README is a wishlist. The thing doesn't entirely work yet!___
         | 
| 7 7 |  | 
| 8 | 
            -
            Campchair provides some helpers for lazily materialized views | 
| 9 | 
            -
             | 
| 8 | 
            +
            Campchair provides some helpers for lazily materialized views,
         | 
| 9 | 
            +
            and gives you a choice of using ActiveRecord-like models
         | 
| 10 | 
            +
            or class-based, barebones data-structure access.
         | 
| 10 11 |  | 
| 11 12 | 
             
            Views are described a bit like those found in [CouchDB](http://couchdb.apache.org/).
         | 
| 12 13 | 
             
            Campchair is not a service and has no client-server stuff.
         | 
| 13 | 
            -
            Parallel  | 
| 14 | 
            +
            Parallel access is not supported yet, but that's okay – you can use something
         | 
| 14 15 | 
             
            else for concurrency and use this in your persistence fiber/thread/process.
         | 
| 16 | 
            +
             | 
| 15 17 | 
             
            Persistence happens through [LevelDB](http://code.google.com/p/leveldb/).
         | 
| 18 | 
            +
            Objects are serialized into documents using Ruby's Marshal class.
         | 
| 16 19 | 
             
            This is not append-only and replication is not a feature.
         | 
| 17 | 
            -
            For these reasons it's called campchair, not couch :)
         | 
| 18 20 |  | 
| 19 | 
            -
            This project was born at [Railscamp 11](http://railscamps.com/) | 
| 21 | 
            +
            This project was born at [Railscamp 11](http://railscamps.com/).
         | 
| 20 22 |  | 
| 21 23 | 
             
            ### How does it look?
         | 
| 22 24 |  | 
| @@ -41,7 +43,7 @@ Mixing in Campchair DB behavior to a class is as simple as... | |
| 41 43 |  | 
| 42 44 | 
             
            ```ruby
         | 
| 43 45 | 
             
            class People
         | 
| 44 | 
            -
              include Campchair:: | 
| 46 | 
            +
              include Campchair::Store
         | 
| 45 47 | 
             
            end
         | 
| 46 48 | 
             
            ```
         | 
| 47 49 |  | 
| @@ -49,20 +51,20 @@ Now, use it like a `Hash`. | |
| 49 51 |  | 
| 50 52 | 
             
            ```ruby
         | 
| 51 53 | 
             
            # Add a document to the db
         | 
| 52 | 
            -
             | 
| 54 | 
            +
            key = People << fred
         | 
| 53 55 |  | 
| 54 56 | 
             
            # Add another person
         | 
| 55 57 | 
             
            People << jane
         | 
| 56 58 |  | 
| 57 59 | 
             
            # Rerieve a document from the db
         | 
| 58 | 
            -
            fred = People[ | 
| 60 | 
            +
            fred = People[key]
         | 
| 59 61 |  | 
| 60 62 | 
             
            # Delete the document from the db
         | 
| 61 | 
            -
            People.delete( | 
| 63 | 
            +
            People.delete(key)
         | 
| 62 64 |  | 
| 63 | 
            -
            # Update/create the document in the db using  | 
| 65 | 
            +
            # Update/create the document in the db using a key
         | 
| 64 66 | 
             
            fred[:last_seen] = Time.new(2012, 3, 6, 12, 40, 25)
         | 
| 65 | 
            -
            doc[ | 
| 67 | 
            +
            doc[key] = fred
         | 
| 66 68 | 
             
            ```
         | 
| 67 69 |  | 
| 68 70 | 
             
            ### Basic views _not yet implemented_
         | 
| @@ -249,7 +251,7 @@ People.average_height_by_location['Docklands, Melbourne, Australia'] | |
| 249 251 |  | 
| 250 252 | 
             
            ### Custom database path
         | 
| 251 253 |  | 
| 252 | 
            -
            By default, the folder for db files is 'cddb'. | 
| 254 | 
            +
            By default, the folder for db files is 'cddb'.
         | 
| 253 255 | 
             
            You can change this with:
         | 
| 254 256 | 
             
            ```ruby
         | 
| 255 257 | 
             
            Campchair.db_path = 'db/heavy_metrics'
         | 
    
        data/campchair.gemspec
    CHANGED
    
    | @@ -8,7 +8,7 @@ Gem::Specification.new do |s| | |
| 8 8 | 
             
              s.authors     = ["Peter Hollows"]
         | 
| 9 9 | 
             
              s.email       = ["pete@dojo7.com"]
         | 
| 10 10 | 
             
              s.homepage    = "https://github.com/captainpete/campchair"
         | 
| 11 | 
            -
              s.summary     = %q{ | 
| 11 | 
            +
              s.summary     = %q{A fast, ghetto-tech CouchDB-like persistence layer for Ruby}
         | 
| 12 12 | 
             
              s.description = %q{Campchair is a map-reduce framework using levelDB for persistence, and Ruby for everything else.}
         | 
| 13 13 |  | 
| 14 14 | 
             
              s.rubyforge_project = "campchair"
         | 
| @@ -18,7 +18,8 @@ Gem::Specification.new do |s| | |
| 18 18 | 
             
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 19 19 | 
             
              s.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 | 
            -
              s.add_dependency | 
| 22 | 
            -
             | 
| 23 | 
            -
              s.add_development_dependency | 
| 21 | 
            +
              s.add_dependency  %q<leveldb-ruby>, ["~> 0.14"]
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              s.add_development_dependency  %q<rspec>,  ["~> 2.12.0"]
         | 
| 24 | 
            +
              s.add_development_dependency  %q<rake>,   ["~> 10.0.0"]
         | 
| 24 25 | 
             
            end
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            module Campchair
         | 
| 2 | 
            +
              module Model
         | 
| 3 | 
            +
                def self.included(base)
         | 
| 4 | 
            +
                  base.class_eval do
         | 
| 5 | 
            +
                    include Store
         | 
| 6 | 
            +
                    extend ClassMethods
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    class << self
         | 
| 9 | 
            +
                      _new = instance_method(:new)
         | 
| 10 | 
            +
                      define_method(:new) do |*args|
         | 
| 11 | 
            +
                        _new.bind(self).call(*args).tap(&:initialize_model)
         | 
| 12 | 
            +
                      end
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                module ClassMethods
         | 
| 18 | 
            +
                  def load(key)
         | 
| 19 | 
            +
                    entity = new
         | 
| 20 | 
            +
                    entity.key = key
         | 
| 21 | 
            +
                    entity.reload
         | 
| 22 | 
            +
                    entity
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def initialize_model
         | 
| 27 | 
            +
                  @attributes = {}
         | 
| 28 | 
            +
                  @new_entity = true
         | 
| 29 | 
            +
                  @destroyed  = false
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                attr_accessor :key
         | 
| 33 | 
            +
                attr_reader :attributes
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def new_entity?
         | 
| 36 | 
            +
                  @new_entity != false
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def destroyed?
         | 
| 40 | 
            +
                  @destroyed != false
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def persisted?
         | 
| 44 | 
            +
                  !(new_entity? || destroyed?)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def save
         | 
| 48 | 
            +
                  if key
         | 
| 49 | 
            +
                    self.class[key] = attributes
         | 
| 50 | 
            +
                  else
         | 
| 51 | 
            +
                    self.key = self.class << attributes
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                  @new_entity = false
         | 
| 54 | 
            +
                  true
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                def delete
         | 
| 58 | 
            +
                  self.class.delete(key) if persisted?
         | 
| 59 | 
            +
                  @destroyed = true
         | 
| 60 | 
            +
                  freeze
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
                alias :destroy :delete
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                def reload(options = nil)
         | 
| 65 | 
            +
                  fresh_attributes = self.class[key]
         | 
| 66 | 
            +
                  attributes.update(fresh_attributes)
         | 
| 67 | 
            +
                  @new_entity = false
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  self
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| @@ -1,8 +1,9 @@ | |
| 1 1 | 
             
            require 'leveldb'
         | 
| 2 | 
            +
            require 'fileutils'
         | 
| 2 3 | 
             
            require 'digest/sha1'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Campchair
         | 
| 5 | 
            -
              module  | 
| 6 | 
            +
              module Store
         | 
| 6 7 | 
             
                class << self
         | 
| 7 8 | 
             
                  def generate_key
         | 
| 8 9 | 
             
                    @alpha ||= [('a'..'f'), ('0'..'9')].map(&:to_a).flatten
         | 
| @@ -19,13 +20,20 @@ module Campchair | |
| 19 20 |  | 
| 20 21 | 
             
                  def included(base)
         | 
| 21 22 | 
             
                    base.class_eval do
         | 
| 23 | 
            +
                      include Enumerable
         | 
| 24 | 
            +
             | 
| 22 25 | 
             
                      class << self
         | 
| 23 | 
            -
                        attr_writer : | 
| 26 | 
            +
                        attr_writer :db_name, :db
         | 
| 24 27 |  | 
| 25 28 | 
             
                        def db_path
         | 
| 26 29 | 
             
                          @db_path || File.join(Campchair.db_path, db_name)
         | 
| 27 30 | 
             
                        end
         | 
| 28 31 |  | 
| 32 | 
            +
                        def db_path=(value)
         | 
| 33 | 
            +
                          @db = nil unless @db_path == value
         | 
| 34 | 
            +
                          @db_path = value
         | 
| 35 | 
            +
                        end
         | 
| 36 | 
            +
             | 
| 29 37 | 
             
                        def db_name
         | 
| 30 38 | 
             
                          @db_name || name
         | 
| 31 39 | 
             
                        end
         | 
| @@ -34,30 +42,42 @@ module Campchair | |
| 34 42 | 
             
                          @db ||= create_db
         | 
| 35 43 | 
             
                        end
         | 
| 36 44 |  | 
| 45 | 
            +
                        def exists?(key)
         | 
| 46 | 
            +
                          db.exists?(key)
         | 
| 47 | 
            +
                        end
         | 
| 48 | 
            +
             | 
| 37 49 | 
             
                        def [](key)
         | 
| 38 50 | 
             
                          val = db[key]
         | 
| 39 | 
            -
                          val && Campchair:: | 
| 51 | 
            +
                          val && Campchair::Store.decode(db[key])
         | 
| 40 52 | 
             
                        end
         | 
| 41 53 |  | 
| 42 54 | 
             
                        def []=(key, value)
         | 
| 43 | 
            -
                          db[key] = Campchair:: | 
| 55 | 
            +
                          db[key] = Campchair::Store.encode(value)
         | 
| 44 56 | 
             
                        end
         | 
| 45 57 |  | 
| 46 58 | 
             
                        def <<(value)
         | 
| 47 | 
            -
                           | 
| 48 | 
            -
                          self[ | 
| 49 | 
            -
                          return  | 
| 59 | 
            +
                          key = Campchair::Store.generate_key
         | 
| 60 | 
            +
                          self[key] = value
         | 
| 61 | 
            +
                          return key
         | 
| 50 62 | 
             
                        end
         | 
| 51 63 |  | 
| 52 64 | 
             
                        def delete(key)
         | 
| 53 65 | 
             
                          db.delete(key)
         | 
| 54 66 | 
             
                        end
         | 
| 55 67 |  | 
| 68 | 
            +
                        def all
         | 
| 69 | 
            +
                          db.keys.map { |key| self[key] }
         | 
| 70 | 
            +
                        end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                        def each(&block)
         | 
| 73 | 
            +
                          db.values.each(&block)
         | 
| 74 | 
            +
                        end
         | 
| 75 | 
            +
             | 
| 56 76 | 
             
                      protected
         | 
| 57 77 |  | 
| 58 78 | 
             
                        def create_db
         | 
| 59 79 | 
             
                          FileUtils.mkdir_p(db_path)
         | 
| 60 | 
            -
                           | 
| 80 | 
            +
                          LevelDB::DB.new(db_path)
         | 
| 61 81 | 
             
                        end
         | 
| 62 82 |  | 
| 63 83 | 
             
                      end # class << self
         | 
| @@ -66,5 +86,5 @@ module Campchair | |
| 66 86 | 
             
                  end # included
         | 
| 67 87 | 
             
                end # class << self
         | 
| 68 88 |  | 
| 69 | 
            -
              end # module  | 
| 89 | 
            +
              end # module Store
         | 
| 70 90 | 
             
            end # module Campchair
         | 
    
        data/lib/campchair/version.rb
    CHANGED
    
    
    
        data/lib/campchair.rb
    CHANGED
    
    | @@ -1,8 +1,9 @@ | |
| 1 1 | 
             
            require "campchair/version"
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Campchair
         | 
| 4 | 
            -
              autoload :Views, | 
| 5 | 
            -
              autoload : | 
| 4 | 
            +
              autoload :Views,  'campchair/views'
         | 
| 5 | 
            +
              autoload :Store,  'campchair/store'
         | 
| 6 | 
            +
              autoload :Model,  'campchair/model'
         | 
| 6 7 |  | 
| 7 8 | 
             
              class << self
         | 
| 8 9 | 
             
                attr_writer :db_path
         | 
| @@ -0,0 +1,95 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Campchair::Model do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              context "included" do
         | 
| 6 | 
            +
                let(:test_class) do
         | 
| 7 | 
            +
                  Class.new { include Campchair::Model }
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                before do
         | 
| 10 | 
            +
                  test_class.stub! :name => 'TestEntity'
         | 
| 11 | 
            +
                  test_class.db_path = 'tmp/ccdb/test'
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                it "includes Campchair::Store" do
         | 
| 15 | 
            +
                  test_class.ancestors.should include(Campchair::Store)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                describe "#load" do
         | 
| 19 | 
            +
                  it "retrieves an object by key, populating attributes, from the store" do
         | 
| 20 | 
            +
                    test_class['BADA55'] = { :colour => 'turple', :awesomeness => '9000' }
         | 
| 21 | 
            +
                    test_entity = test_class.load('BADA55')
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    test_entity.should be_a(test_class)
         | 
| 24 | 
            +
                    test_entity.attributes.should == { :colour => 'turple', :awesomeness => '9000' }
         | 
| 25 | 
            +
                    test_entity.should be_persisted
         | 
| 26 | 
            +
                    test_entity.should_not be_new_entity
         | 
| 27 | 
            +
                    test_entity.should_not be_destroyed
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                describe "#save" do
         | 
| 32 | 
            +
                  context "when not previously persisted (create)" do
         | 
| 33 | 
            +
                    let(:test_entity) do
         | 
| 34 | 
            +
                      test_class.new
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                    before do
         | 
| 37 | 
            +
                      test_entity.should_not be_persisted
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    context "the model has no key" do
         | 
| 41 | 
            +
                      before do
         | 
| 42 | 
            +
                        test_entity.key.should be_nil
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                      it "adds an attribute hash to the store and sets the model key to the generated store key" do
         | 
| 46 | 
            +
                        test_entity.stub! :attributes => { :paper => 'is for planes' }
         | 
| 47 | 
            +
                        test_entity.save
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                        key = test_entity.key
         | 
| 50 | 
            +
                        key.should_not be_nil
         | 
| 51 | 
            +
                        test_class[key].should == { :paper => 'is for planes' }
         | 
| 52 | 
            +
                      end
         | 
| 53 | 
            +
                    end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    context "the model has a key" do
         | 
| 56 | 
            +
                      it "writes an attribute hash to the store keyed by the model's key" do
         | 
| 57 | 
            +
                      end
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  context "when already persisted (update)" do
         | 
| 62 | 
            +
                    let(:test_entity) do
         | 
| 63 | 
            +
                      test_class['BADA55'] = { :colour => 'turple', :awesomeness => '9000' }
         | 
| 64 | 
            +
                      test_class.load('BADA55')
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                    before do
         | 
| 67 | 
            +
                      test_entity.should be_persisted
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    it "updates the attribute hash stored at the model's key, using the model's attributes" do
         | 
| 71 | 
            +
                      test_entity.stub! :key => 'BADA55', :attributes => { :taste => 'like tripping', :awesomeness => '9001' }
         | 
| 72 | 
            +
                      test_entity.save
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                      test_class['BADA55'].should == { :taste => 'like tripping', :awesomeness => '9001' }
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                end # describe "#save"
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                describe "#delete" do
         | 
| 81 | 
            +
                  it "removes the object from the store" do
         | 
| 82 | 
            +
                    test_entity = test_class.new
         | 
| 83 | 
            +
                    test_entity.key = 'BADA55'
         | 
| 84 | 
            +
                    test_entity.save
         | 
| 85 | 
            +
                    test_entity.should be_persisted
         | 
| 86 | 
            +
                    test_class.should be_exists('BADA55')
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    test_entity.delete
         | 
| 89 | 
            +
                    test_entity.should be_destroyed
         | 
| 90 | 
            +
                    test_class.should_not be_exists('BADA55')
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              end # context "included"
         | 
| 95 | 
            +
            end # describe Campchair::Model
         | 
| @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 | 
            -
            describe Campchair:: | 
| 3 | 
            +
            describe Campchair::Store do
         | 
| 4 4 | 
             
              let(:test_module) do
         | 
| 5 | 
            -
                Campchair:: | 
| 5 | 
            +
                Campchair::Store.dup
         | 
| 6 6 | 
             
              end
         | 
| 7 7 |  | 
| 8 8 | 
             
              describe ".generate_key" do
         | 
| @@ -13,26 +13,21 @@ describe Campchair::LevelDB do | |
| 13 13 |  | 
| 14 14 | 
             
              context "included" do
         | 
| 15 15 | 
             
                let(:test_class) do
         | 
| 16 | 
            -
                   | 
| 17 | 
            -
                  TestEntity = Class.new do
         | 
| 18 | 
            -
                    include Campchair::LevelDB
         | 
| 19 | 
            -
                  end
         | 
| 16 | 
            +
                  Class.new { include Campchair::Store }
         | 
| 20 17 | 
             
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
                  `rm -fr tmp/ccdb`
         | 
| 18 | 
            +
                before do
         | 
| 19 | 
            +
                  test_class.stub! :name => 'TestEntity'
         | 
| 24 20 | 
             
                end
         | 
| 25 21 |  | 
| 26 22 | 
             
                describe "setting the db_name" do
         | 
| 27 23 | 
             
                  describe ".db_name" do
         | 
| 28 24 | 
             
                    it "is the class name by default" do
         | 
| 29 | 
            -
                      test_class.stub! :name => 'TestEntity'
         | 
| 30 25 | 
             
                      test_class.db_name.should == 'TestEntity'
         | 
| 31 26 | 
             
                    end
         | 
| 32 27 | 
             
                  end
         | 
| 33 28 |  | 
| 34 29 | 
             
                  describe ".db_name=" do
         | 
| 35 | 
            -
                    it " | 
| 30 | 
            +
                    it "sets the db_name" do
         | 
| 36 31 | 
             
                      test_class.db_name = 'TestEntityCustomName'
         | 
| 37 32 | 
             
                      test_class.db_name.should == 'TestEntityCustomName'
         | 
| 38 33 | 
             
                    end
         | 
| @@ -43,12 +38,14 @@ describe Campchair::LevelDB do | |
| 43 38 | 
             
                  describe ".db_path" do
         | 
| 44 39 | 
             
                    it "is the Campchair.db_path, and the db_name by default" do
         | 
| 45 40 | 
             
                      Campchair.should_receive(:db_path).and_return('some/path')
         | 
| 41 | 
            +
                      test_class.should_receive(:db_name).and_return('TestEntity')
         | 
| 42 | 
            +
             | 
| 46 43 | 
             
                      test_class.db_path.should == 'some/path/TestEntity'
         | 
| 47 44 | 
             
                    end
         | 
| 48 45 | 
             
                  end
         | 
| 49 46 |  | 
| 50 47 | 
             
                  describe ".db_path=" do
         | 
| 51 | 
            -
                    it " | 
| 48 | 
            +
                    it "sets the db_path" do
         | 
| 52 49 | 
             
                      test_class.db_path = 'some/other/path'
         | 
| 53 50 | 
             
                      test_class.db_path.should == 'some/other/path'
         | 
| 54 51 | 
             
                    end
         | 
| @@ -65,20 +62,44 @@ describe Campchair::LevelDB do | |
| 65 62 | 
             
                      test_class.db.should be_a(LevelDB::DB)
         | 
| 66 63 | 
             
                      test_class.db.pathname.should == 'tmp/ccdb/test'
         | 
| 67 64 | 
             
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    it "is cached" do
         | 
| 67 | 
            +
                      test_class.db.should == test_class.db
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    it "changes to reflect changes to db_path" do
         | 
| 71 | 
            +
                      first_db = test_class.db
         | 
| 72 | 
            +
                      test_class.db_path = 'tmp/ccdb/test2'
         | 
| 73 | 
            +
                      second_db = test_class.db
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                      first_db.should_not == second_db
         | 
| 76 | 
            +
                      second_db.pathname.should == 'tmp/ccdb/test2'
         | 
| 77 | 
            +
                    end
         | 
| 68 78 | 
             
                  end
         | 
| 69 79 |  | 
| 70 80 | 
             
                  context "no data serialization" do
         | 
| 71 81 | 
             
                    before do
         | 
| 72 82 | 
             
                      # Passthrough {en,de}coding for these tests
         | 
| 73 | 
            -
                      Campchair:: | 
| 74 | 
            -
                      Campchair:: | 
| 83 | 
            +
                      Campchair::Store.stub(:encode).and_return {|v| v}
         | 
| 84 | 
            +
                      Campchair::Store.stub(:decode).and_return {|v| v}
         | 
| 75 85 |  | 
| 76 86 | 
             
                      FileUtils.mkdir_p('tmp/ccdb/TestEntity')
         | 
| 77 | 
            -
                      @db =  | 
| 87 | 
            +
                      @db = LevelDB::DB.new('tmp/ccdb/TestEntity')
         | 
| 78 88 |  | 
| 79 89 | 
             
                      test_class.stub! :db => @db
         | 
| 80 90 | 
             
                    end
         | 
| 81 91 |  | 
| 92 | 
            +
                    describe ".exists?" do
         | 
| 93 | 
            +
                      it "is false when there's no matching key in the database" do
         | 
| 94 | 
            +
                        test_class.exists?('nonexistent').should be_false
         | 
| 95 | 
            +
                      end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                      it "is true when there's a matching key" do
         | 
| 98 | 
            +
                        @db['something'] = '22'
         | 
| 99 | 
            +
                        test_class.exists?('something').should be_true
         | 
| 100 | 
            +
                      end
         | 
| 101 | 
            +
                    end
         | 
| 102 | 
            +
             | 
| 82 103 | 
             
                    describe ".[]" do
         | 
| 83 104 | 
             
                      it "is nil when there's no matching key in the database" do
         | 
| 84 105 | 
             
                        test_class['nonexistent'].should be_nil
         | 
| @@ -98,13 +119,13 @@ describe Campchair::LevelDB do | |
| 98 119 | 
             
                    end
         | 
| 99 120 |  | 
| 100 121 | 
             
                    describe ".<<" do
         | 
| 101 | 
            -
                      it "adds the value to the database,  | 
| 122 | 
            +
                      it "adds the value to the database, returning a key" do
         | 
| 102 123 | 
             
                        key = 'b78aa2f6b718651743fac2682003f2c63340ae34b'
         | 
| 103 | 
            -
                        Campchair:: | 
| 124 | 
            +
                        Campchair::Store.stub! :generate_key => key
         | 
| 104 125 |  | 
| 105 | 
            -
                         | 
| 106 | 
            -
                         | 
| 107 | 
            -
                        test_class[ | 
| 126 | 
            +
                        generated_key = test_class << '22'
         | 
| 127 | 
            +
                        generated_key.should == key
         | 
| 128 | 
            +
                        test_class[generated_key].should == '22'
         | 
| 108 129 | 
             
                      end
         | 
| 109 130 | 
             
                    end
         | 
| 110 131 |  | 
| @@ -112,13 +133,35 @@ describe Campchair::LevelDB do | |
| 112 133 | 
             
                      it "deletes the key its values from the db" do
         | 
| 113 134 | 
             
                        test_class['something'] = '22'
         | 
| 114 135 | 
             
                        test_class.delete('something')
         | 
| 115 | 
            -
             | 
| 136 | 
            +
             | 
| 116 137 | 
             
                        test_class['something'].should be_nil
         | 
| 117 138 | 
             
                      end
         | 
| 118 139 | 
             
                    end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                    describe ".all" do
         | 
| 142 | 
            +
                      it "contains all the values" do
         | 
| 143 | 
            +
                        test_class << '22'
         | 
| 144 | 
            +
                        test_class << '22'
         | 
| 145 | 
            +
                        test_class << '44'
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                        test_class.all.sort == ['22', '22', '44']
         | 
| 148 | 
            +
                      end
         | 
| 149 | 
            +
                    end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                    describe ".each" do
         | 
| 152 | 
            +
                      it "enumerates over all the values" do
         | 
| 153 | 
            +
                        test_class << '22'
         | 
| 154 | 
            +
                        test_class << '22'
         | 
| 155 | 
            +
                        test_class << '44'
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                        values = []
         | 
| 158 | 
            +
                        test_class.each { |v| values << v }
         | 
| 159 | 
            +
                        values.sort.should == ['22', '22', '44']
         | 
| 160 | 
            +
                      end
         | 
| 161 | 
            +
                    end
         | 
| 119 162 | 
             
                  end
         | 
| 120 163 |  | 
| 121 | 
            -
                  context "Campchair:: | 
| 164 | 
            +
                  context "Campchair::Store serialization" do
         | 
| 122 165 | 
             
                    describe ".[]{,=}" do
         | 
| 123 166 | 
             
                      it "persists non-string data structures" do
         | 
| 124 167 | 
             
                        doc = { :sym => :sym, 'string' => 'string', 'types' => [1234.12341234, (55..44), /regexen/, Time.now, { 'a' => 22 }] }
         | 
| @@ -16,7 +16,7 @@ describe "DB behavior" do | |
| 16 16 | 
             
                }
         | 
| 17 17 |  | 
| 18 18 | 
             
                class TestPeople
         | 
| 19 | 
            -
                  include Campchair:: | 
| 19 | 
            +
                  include Campchair::Store
         | 
| 20 20 | 
             
                  self.db_path = 'tmp/ccdb'
         | 
| 21 21 | 
             
                end
         | 
| 22 22 | 
             
              end
         | 
| @@ -25,36 +25,31 @@ describe "DB behavior" do | |
| 25 25 | 
             
                `rm -fr tmp/ccdb`
         | 
| 26 26 | 
             
              end
         | 
| 27 27 |  | 
| 28 | 
            -
              it "persists documents | 
| 29 | 
            -
                 | 
| 30 | 
            -
                TestPeople | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              it "retrieves documents" do
         | 
| 34 | 
            -
                id = TestPeople << @fred
         | 
| 35 | 
            -
                TestPeople[id].should == @fred
         | 
| 28 | 
            +
              it "persists documents" do
         | 
| 29 | 
            +
                key = TestPeople << @fred
         | 
| 30 | 
            +
                TestPeople[key].should == @fred
         | 
| 36 31 | 
             
              end
         | 
| 37 32 |  | 
| 38 33 | 
             
              it "deletes documents" do
         | 
| 39 | 
            -
                 | 
| 40 | 
            -
                TestPeople.delete( | 
| 41 | 
            -
                TestPeople[ | 
| 34 | 
            +
                key = TestPeople << @fred
         | 
| 35 | 
            +
                TestPeople.delete(key)
         | 
| 36 | 
            +
                TestPeople[key].should be_nil
         | 
| 42 37 | 
             
              end
         | 
| 43 38 |  | 
| 44 | 
            -
              it "updates docuemnts with  | 
| 45 | 
            -
                 | 
| 39 | 
            +
              it "updates docuemnts with a key" do
         | 
| 40 | 
            +
                key = TestPeople << @fred
         | 
| 46 41 | 
             
                new_last_seen = Time.local(2012, 3, 6, 12, 50)
         | 
| 47 42 | 
             
                @fred[:last_seen] = new_last_seen
         | 
| 48 | 
            -
                TestPeople[ | 
| 43 | 
            +
                TestPeople[key] = @fred
         | 
| 49 44 |  | 
| 50 | 
            -
                TestPeople[ | 
| 45 | 
            +
                TestPeople[key][:last_seen].should == new_last_seen
         | 
| 51 46 | 
             
              end
         | 
| 52 47 |  | 
| 53 | 
            -
              it "creates documents with  | 
| 54 | 
            -
                 | 
| 55 | 
            -
                TestPeople[ | 
| 48 | 
            +
              it "creates documents with a key" do
         | 
| 49 | 
            +
                key = 'something'
         | 
| 50 | 
            +
                TestPeople[key] = @fred
         | 
| 56 51 |  | 
| 57 | 
            -
                TestPeople[ | 
| 52 | 
            +
                TestPeople[key].should == @fred
         | 
| 58 53 | 
             
              end
         | 
| 59 54 |  | 
| 60 55 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: campchair
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-11-16 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: leveldb-ruby
         | 
| 16 | 
            -
              requirement:  | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,29 +21,44 @@ dependencies: | |
| 21 21 | 
             
                    version: '0.14'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements:  | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '0.14'
         | 
| 25 30 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 31 | 
             
              name: rspec
         | 
| 27 | 
            -
              requirement:  | 
| 32 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 28 33 | 
             
                none: false
         | 
| 29 34 | 
             
                requirements:
         | 
| 30 | 
            -
                - -  | 
| 35 | 
            +
                - - ~>
         | 
| 31 36 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version:  | 
| 37 | 
            +
                    version: 2.12.0
         | 
| 33 38 | 
             
              type: :development
         | 
| 34 39 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements:  | 
| 40 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
                none: false
         | 
| 42 | 
            +
                requirements:
         | 
| 43 | 
            +
                - - ~>
         | 
| 44 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                    version: 2.12.0
         | 
| 36 46 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 47 | 
             
              name: rake
         | 
| 38 | 
            -
              requirement:  | 
| 48 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 39 49 | 
             
                none: false
         | 
| 40 50 | 
             
                requirements:
         | 
| 41 | 
            -
                - -  | 
| 51 | 
            +
                - - ~>
         | 
| 42 52 | 
             
                  - !ruby/object:Gem::Version
         | 
| 43 | 
            -
                    version:  | 
| 53 | 
            +
                    version: 10.0.0
         | 
| 44 54 | 
             
              type: :development
         | 
| 45 55 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements:  | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                none: false
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ~>
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 10.0.0
         | 
| 47 62 | 
             
            description: Campchair is a map-reduce framework using levelDB for persistence, and
         | 
| 48 63 | 
             
              Ruby for everything else.
         | 
| 49 64 | 
             
            email:
         | 
| @@ -60,11 +75,13 @@ files: | |
| 60 75 | 
             
            - Rakefile
         | 
| 61 76 | 
             
            - campchair.gemspec
         | 
| 62 77 | 
             
            - lib/campchair.rb
         | 
| 63 | 
            -
            - lib/campchair/ | 
| 78 | 
            +
            - lib/campchair/model.rb
         | 
| 79 | 
            +
            - lib/campchair/store.rb
         | 
| 64 80 | 
             
            - lib/campchair/version.rb
         | 
| 65 81 | 
             
            - lib/campchair/views.rb
         | 
| 66 82 | 
             
            - spec/.gitkeep
         | 
| 67 | 
            -
            - spec/campchair/ | 
| 83 | 
            +
            - spec/campchair/model_spec.rb
         | 
| 84 | 
            +
            - spec/campchair/store_spec.rb
         | 
| 68 85 | 
             
            - spec/campchair/views_spec.rb
         | 
| 69 86 | 
             
            - spec/campchair_spec.rb
         | 
| 70 87 | 
             
            - spec/integration/readme_examples_spec.rb
         | 
| @@ -90,12 +107,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 90 107 | 
             
                  version: '0'
         | 
| 91 108 | 
             
            requirements: []
         | 
| 92 109 | 
             
            rubyforge_project: campchair
         | 
| 93 | 
            -
            rubygems_version: 1.8. | 
| 110 | 
            +
            rubygems_version: 1.8.24
         | 
| 94 111 | 
             
            signing_key: 
         | 
| 95 112 | 
             
            specification_version: 3
         | 
| 96 | 
            -
            summary:  | 
| 113 | 
            +
            summary: A fast, ghetto-tech CouchDB-like persistence layer for Ruby
         | 
| 97 114 | 
             
            test_files:
         | 
| 98 | 
            -
            - spec/campchair/ | 
| 115 | 
            +
            - spec/campchair/model_spec.rb
         | 
| 116 | 
            +
            - spec/campchair/store_spec.rb
         | 
| 99 117 | 
             
            - spec/campchair/views_spec.rb
         | 
| 100 118 | 
             
            - spec/campchair_spec.rb
         | 
| 101 119 | 
             
            - spec/integration/readme_examples_spec.rb
         |