Skip to content

Commit

Permalink
Changed classes from couchrest to couchbase
Browse files Browse the repository at this point in the history
  • Loading branch information
jethar committed Sep 3, 2011
1 parent 66f937c commit 34e9e80
Show file tree
Hide file tree
Showing 87 changed files with 405 additions and 390 deletions.
18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>couchbase_model</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.ruby.core.rubynature</nature>
<nature>com.aptana.projects.webnature</nature>
</natures>
</projectDescription>
51 changes: 24 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# CouchRest Model: CouchDB, close to shiny metal with rounded edges
# CouchBase Model: CouchBase, working on the new CouchBase Server

CouchRest Models adds additional functionality to the standard CouchRest Document class such as
setting properties, callbacks, typecasting, and validations.
CouchBase Models, built from CouchBase Model is an effort to provide model interface on the offical ruby gem for couchbase - couchbase-ruby-client.

## Documentation

Please visit the documentation project at [http://www.couchrest.info](http://www.couchrest.info). You're [contributions](https://github.com/couchrest/couchrest.github.com) to the documentation would be greatly appreciated!
General API: [http://rdoc.info/projects/jethar/couchbase_model](http://rdoc.info/projects/couchbase/couchbase_model)

General API: [http://rdoc.info/projects/couchrest/couchrest_model](http://rdoc.info/projects/couchrest/couchrest_model)
See the [update history](https://github.com/jethar/couchbase_model/blob/master/history.md) for an up to date list of all the changes we've been working on recently.

See the [update history](https://github.com/couchrest/couchrest_model/blob/master/history.md) for an up to date list of all the changes we've been working on recently.

## Notes
## Notes on CouchRest Model

Originally called ExtendedDocument, the new Model structure uses ActiveModel, part of Rails 3,
for validations and callbacks.
Expand All @@ -21,31 +18,31 @@ it is not possible to load ActiveModel into programs that do not use ActiveSuppo

CouchRest Model is only properly tested on CouchDB version 1.0 or newer.

*WARNING:* As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:
*WARNING:* As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchbase-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:

CouchRest::Model::Base.configure do |config|
config.model_type_key = 'couchrest-type'
CouchBase::Model::Base.configure do |config|
config.model_type_key = 'couchbase-type'
end

This is because CouchRest Model's are not couchrest specific and may be used in any other systems such as Javascript, the model type should reflect this. Also, we're all used to `type` being a reserved word in ActiveRecord.
This is because CouchBase Model's are not couchbase specific and may be used in any other systems such as Javascript, the model type should reflect this. Also, we're all used to `type` being a reserved word in ActiveRecord.

## Install

### Gem

$ sudo gem install couchrest_model
$ sudo gem install couchbase_model

### Bundler

If you're using bundler, define a line similar to the following in your project's Gemfile:

gem 'couchrest_model'
gem 'couchbase_model'

### Configuration

CouchRest Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (5984) on localhost. The default name of the database is either the name of your application as provided by the `Rails.application.class.to_s` call (with /application removed) or just 'couchrest' if none is available.
CouchBase Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (8091) on localhost. The default name of the database is either the name of your application as provided by the `Rails.application.class.to_s` call (with /application removed) or just 'couchbase' if none is available.

The library will try to detect a configuration file at `config/couchdb.yml` from the Rails root or `Dir.pwd`. Here you can configuration your database connection in a Rails-like way:
The library will try to detect a configuration file at `config/couchbase.yml` from the Rails root or `Dir.pwd`. Here you can configuration your database connection in a Rails-like way:

development:
protocol: 'https'
Expand All @@ -60,7 +57,7 @@ Note that the name of the database is either just the prefix and suffix combined

The example config above for example would use a database called "project_test". Heres an example using the `use_database` call:

class Project < CouchRest::Model::Base
class Project < CouchBase::Model::Base
use_database 'sample'
end

Expand All @@ -72,17 +69,17 @@ The example config above for example would use a database called "project_test".

### Configuration

$ rails generate couchrest_model:config
$ rails generate couchbase_model:config

### Model

$ rails generate model person --orm=couchrest_model
$ rails generate model person --orm=couchbase_model

## General Usage

require 'couchrest_model'
require 'couchbase_model'

class Cat < CouchRest::Model::Base
class Cat < CouchBase::Model::Base

property :name, String
property :lives, Integer, :default => 9
Expand Down Expand Up @@ -113,25 +110,25 @@ The example config above for example would use a database called "project_test".

### Preparations

CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
CouchBase Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:

bundle install

That should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations
That should set everything up for `rake spec` to be run correctly. Update the couchbase_model.gemspec if your alterations
use different gems.

### Testing

The most complete documentation is the spec/ directory. To validate your CouchRest install, from the project root directory run `bundle install` to ensure all the development dependencies are available and then `rspec spec` or `bundle exec rspec spec`.
The most complete documentation is the spec/ directory. To validate your CouchBase install, from the project root directory run `bundle install` to ensure all the development dependencies are available and then `rspec spec` or `bundle exec rspec spec`.

We will not accept pull requests to the project without sufficient tests.

## Contact

Please post bugs, suggestions and patches to the bug tracker at [http://github.com/couchrest/couchrest_model/issues](http://github.com/couchrest/couchrest_model/issues).
Please post bugs, suggestions and patches to the bug tracker at [http://github.com/couchbase/couchbase_model/issues](http://github.com/couchbase/couchbase_model/issues).

Follow us on Twitter: [http://twitter.com/couchrest](http://twitter.com/couchrest)
Follow us on Twitter: [http://twitter.com/couchbase](http://twitter.com/couchbase)

Also, check [http://twitter.com/#search?q=%23couchrest](http://twitter.com/#search?q=%23couchrest)
Also, check [http://twitter.com/#search?q=%23couchbase](http://twitter.com/#search?q=%23couchbase)


2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Rake::RDocTask.new do |rdoc|
files = ["README.rdoc", "LICENSE", "lib/**/*.rb"]
rdoc.rdoc_files.add(files)
rdoc.main = "README.rdoc"
rdoc.title = "CouchRest: Ruby CouchDB, close to the metal"
rdoc.title = "CouchBase: Ruby CouchBase, Working with new CouchBase Server"
end

desc "Run the rspec"
Expand Down
4 changes: 2 additions & 2 deletions THANKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CouchRest THANKS

CouchRest was originally developed by J. Chris Anderson <[email protected]>
and a number of other contributors. Many people further contributed to
CouchRest by reporting problems, suggesting various improvements or submitting
CouchBase by reporting problems, suggesting various improvements or submitting
changes. A list of these people is included below.

* [Matt Aimonetti](http://merbist.com/about/)
Expand All @@ -16,6 +16,6 @@ changes. A list of these people is included below.
* [Sam Lown](http://github.com/samlown)
* [Will Leinweber](http://github.com/will)

Patches are welcome. The primary source for this software project is [on Github](http://github.com/couchrest/couchrest)
Patches are welcome. The primary source for this software project is [on Github](http://github.com/jethar/couchbase_model)

A lot of people have active forks - thank you all - even the patches I don't end up using are helpful.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
0.0.1
12 changes: 6 additions & 6 deletions benchmarks/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require 'benchmark'

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'couchrest_model'
require 'couchbase_model'

class BenchmarkCasted < Hash
include CouchRest::Model::CastedModel
include CouchBase::Model::CastedModel

property :name
end

class BenchmarkModel < CouchRest::Model::Base
use_database CouchRest.database!(ENV['BENCHMARK_DB'] || "http://localhost:5984/test")
class BenchmarkModel < CouchBase::Model::Base
use_database CouchBase.database!(ENV['BENCHMARK_DB'] || "http://localhost:8091/test")

property :string, String
property :number, Integer
Expand All @@ -24,7 +24,7 @@ class BenchmarkModel < CouchRest::Model::Base
# set dirty configuration, return previous configuration setting
def set_dirty(value)
orig = nil
CouchRest::Model::Base.configure do |config|
CouchBase::Model::Base.configure do |config|
orig = config.use_dirty
config.use_dirty = value
end
Expand All @@ -35,7 +35,7 @@ def set_dirty(value)
end

def supports_dirty?
CouchRest::Model::Base.respond_to?(:use_dirty)
CouchBase::Model::Base.respond_to?(:use_dirty)
end

def run_benchmark
Expand Down
10 changes: 5 additions & 5 deletions couchbase_model.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{couchrest_model}
s.name = %q{couchbase_model}
s.version = `cat VERSION`.strip

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
s.date = File.mtime('VERSION')
s.description = %q{CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.}
s.description = %q{CouchBase Model provides aditional features to the standard CouchBase Document class such as properties, view designs, associations, callbacks, typecasting and validations.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"LICENSE",
"README.md",
"THANKS.md"
]
s.homepage = %q{http://github.com/couchrest/couchrest_model}
s.homepage = %q{http://github.com/couchbase/couchbase_model}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Extends the CouchRest Document for advanced modelling.}
s.summary = %q{Extends the CouchBase Document for advanced modelling.}

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(%q<couchrest>, "~> 1.1.2")
s.add_dependency(%q<couchbase>, "~> 1.1.2")
s.add_dependency(%q<mime-types>, "~> 1.15")
s.add_dependency(%q<activemodel>, "~> 3.0")
s.add_dependency(%q<tzinfo>, "~> 0.3.22")
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require File.join(File.dirname(__FILE__),'lib', 'couchrest', 'model')
require File.join(File.dirname(__FILE__),'lib', 'couchbase', 'model')
2 changes: 1 addition & 1 deletion lib/couchbase/model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

module CouchRest
module CouchBase

module Model

Expand Down
8 changes: 4 additions & 4 deletions lib/couchbase/model/associations.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module CouchRest
module CouchBase
module Model
module Associations

# Basic support for relationships between CouchRest::Model::Base
# Basic support for relationships between CouchBase::Model::Base

def self.included(base)
base.extend(ClassMethods)
Expand Down Expand Up @@ -153,15 +153,15 @@ def create_collection_of_getter(attrib, options)
def #{attrib}(reload = false)
return @#{attrib} unless @#{attrib}.nil? or reload
ary = self.#{options[:foreign_key]}.collect{|i| #{options[:proxy]}.get(i)}
@#{attrib} = ::CouchRest::Model::CollectionOfProxy.new(ary, find_property('#{options[:foreign_key]}'), self)
@#{attrib} = ::CouchBase::Model::CollectionOfProxy.new(ary, find_property('#{options[:foreign_key]}'), self)
end
EOS
end

def create_collection_of_setter(attrib, options)
class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{attrib}=(value)
@#{attrib} = ::CouchRest::Model::CollectionOfProxy.new(value, find_property('#{options[:foreign_key]}'), self)
@#{attrib} = ::CouchBase::Model::CollectionOfProxy.new(value, find_property('#{options[:foreign_key]}'), self)
end
EOS
end
Expand Down
46 changes: 23 additions & 23 deletions lib/couchbase/model/base.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
module CouchRest
module CouchBase
module Model
class Base < CouchRest::Document
class Base < CouchBase::Document

extend ActiveModel::Naming

include CouchRest::Model::Configuration
include CouchRest::Model::Connection
include CouchRest::Model::Persistence
include CouchRest::Model::DocumentQueries
include CouchRest::Model::Views
include CouchRest::Model::DesignDoc
include CouchRest::Model::ExtendedAttachments
include CouchRest::Model::ClassProxy
include CouchRest::Model::Proxyable
include CouchRest::Model::Collection
include CouchRest::Model::PropertyProtection
include CouchRest::Model::Associations
include CouchRest::Model::Validations
include CouchRest::Model::Callbacks
include CouchRest::Model::Designs
include CouchRest::Model::CastedBy
include CouchRest::Model::Dirty
include CouchRest::Model::Callbacks
include CouchBase::Model::Configuration
include CouchBase::Model::Connection
include CouchBase::Model::Persistence
include CouchBase::Model::DocumentQueries
include CouchBase::Model::Views
include CouchBase::Model::DesignDoc
include CouchBase::Model::ExtendedAttachments
include CouchBase::Model::ClassProxy
include CouchBase::Model::Proxyable
include CouchBase::Model::Collection
include CouchBase::Model::PropertyProtection
include CouchBase::Model::Associations
include CouchBase::Model::Validations
include CouchBase::Model::Callbacks
include CouchBase::Model::Designs
include CouchBase::Model::CastedBy
include CouchBase::Model::Dirty
include CouchBase::Model::Callbacks

def self.subclasses
@subclasses ||= []
end

def self.inherited(subklass)
super
subklass.send(:include, CouchRest::Model::Properties)
subklass.send(:include, CouchBase::Model::Properties)

subklass.class_eval <<-EOS, __FILE__, __LINE__ + 1
def self.inherited(subklass)
Expand All @@ -42,7 +42,7 @@ def self.inherited(subklass)
subclasses << subklass
end

# Instantiate a new CouchRest::Model::Base by preparing all properties
# Instantiate a new CouchBase::Model::Base by preparing all properties
# using the provided document hash.
#
# Options supported:
Expand Down Expand Up @@ -111,7 +111,7 @@ def to_key
# Camparison of the database is required in case the
# model has been proxied or loaded elsewhere.
#
# A Basic CouchRest document will only ever compare using
# A Basic CouchBase document will only ever compare using
# a Hash comparison on the attributes.
def == other
return false unless other.is_a?(Base)
Expand Down
2 changes: 1 addition & 1 deletion lib/couchbase/model/callbacks.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8

module CouchRest #:nodoc:
module CouchBase #:nodoc:
module Model #:nodoc:

module Callbacks
Expand Down
Loading

0 comments on commit 34e9e80

Please sign in to comment.