Merge remote branch 'remotes/old/master'

Conflicts:
	README.md
	couchrest.gemspec
	lib/couchrest.rb
	lib/couchrest/mixins/properties.rb
This commit is contained in:
Tapajós 2009-09-03 23:10:06 -03:00
commit 3c2ebb022d
9 changed files with 51 additions and 7 deletions

View file

@ -124,6 +124,13 @@ CouchRest uses a mixin you can find in lib/mixins/callbacks which is extracted f
Check the mixin or the ExtendedDocument class to see how to implement your own callbacks.
### Properties
property :last_name, :alias => :family_name
property :read_only_value, :read_only => true
property :name, :length => 4...20
property :price, :type => Integer
### Casting
Often, you will want to store multiple objects within a document, to be able to retrieve your objects when you load the document,
@ -131,7 +138,10 @@ you can define some casting rules.
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
property :keywords, :cast_as => ["String"]
property :occurs_at, :cast_as => 'Time'
property :end_date, :cast_as => 'Date'
<<<<<<< HEAD
If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"]
### Pagination
@ -163,3 +173,6 @@ Low level usage:
CouchRest is compatible with rails and can even be used a Rails plugin.
However, you might be interested in the CouchRest companion rails project:
[http://github.com/hpoydar/couchrest-rails](http://github.com/hpoydar/couchrest-rails)
=======
If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"]
>>>>>>> remotes/old/master

View file

@ -12,6 +12,7 @@ changes. A list of these people is included below.
* [Jonathan S. Katz](http://github.com/jkatz)
* [Matt Lyon](http://mattly.tumblr.com/)
* Simon Rozet (simon /at/ rozet /dot/ name)
* [Marcos Tapajós](http://tapajos.me)
Patches are welcome. The primary source for this software project is [on Github](http://github.com/jchris/couchrest/tree/master)

View file

@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{couchrest}
s.version = "0.33"
s.version = "0.34"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti"]
@ -11,14 +11,15 @@ Gem::Specification.new do |s|
s.email = %q{jchris@apache.org}
s.extra_rdoc_files = ["README.md", "LICENSE", "THANKS.md"]
s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "history.txt", "examples/model", "examples/model/example.rb", "examples/word_count", "examples/word_count/markov", "examples/word_count/views", "examples/word_count/views/books", "examples/word_count/views/books/chunked-map.js", "examples/word_count/views/books/united-map.js", "examples/word_count/views/markov", "examples/word_count/views/markov/chain-map.js", "examples/word_count/views/markov/chain-reduce.js", "examples/word_count/views/word_count", "examples/word_count/views/word_count/count-map.js", "examples/word_count/views/word_count/count-reduce.js", "examples/word_count/word_count.rb", "examples/word_count/word_count_query.rb", "examples/word_count/word_count_views.rb", "lib/couchrest", "lib/couchrest/commands", "lib/couchrest/commands/generate.rb", "lib/couchrest/commands/push.rb", "lib/couchrest/core", "lib/couchrest/core/adapters", "lib/couchrest/core/adapters/restclient.rb", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/http_abstraction.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/rest_api.rb", "lib/couchrest/core/server.rb", "lib/couchrest/core/view.rb", "lib/couchrest/helper", "lib/couchrest/helper/pager.rb", "lib/couchrest/helper/streamer.rb", "lib/couchrest/helper/upgrade.rb", "lib/couchrest/middlewares", "lib/couchrest/middlewares/logger.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/class_proxy.rb", "lib/couchrest/mixins/collection.rb", "lib/couchrest/mixins/design_doc.rb", "lib/couchrest/mixins/document_queries.rb", "lib/couchrest/mixins/extended_attachments.rb", "lib/couchrest/mixins/extended_document_mixins.rb", "lib/couchrest/mixins/properties.rb", "lib/couchrest/mixins/validation.rb", "lib/couchrest/mixins/views.rb", "lib/couchrest/mixins.rb", "lib/couchrest/monkeypatches.rb", "lib/couchrest/more", "lib/couchrest/more/casted_model.rb", "lib/couchrest/more/extended_document.rb", "lib/couchrest/more/property.rb", "lib/couchrest/support", "lib/couchrest/support/blank.rb", "lib/couchrest/support/class.rb", "lib/couchrest/support/rails.rb", "lib/couchrest/validation", "lib/couchrest/validation/auto_validate.rb", "lib/couchrest/validation/contextual_validators.rb", "lib/couchrest/validation/validation_errors.rb", "lib/couchrest/validation/validators", "lib/couchrest/validation/validators/absent_field_validator.rb", "lib/couchrest/validation/validators/confirmation_validator.rb", "lib/couchrest/validation/validators/format_validator.rb", "lib/couchrest/validation/validators/formats", "lib/couchrest/validation/validators/formats/email.rb", "lib/couchrest/validation/validators/formats/url.rb", "lib/couchrest/validation/validators/generic_validator.rb", "lib/couchrest/validation/validators/length_validator.rb", "lib/couchrest/validation/validators/method_validator.rb", "lib/couchrest/validation/validators/numeric_validator.rb", "lib/couchrest/validation/validators/required_field_validator.rb", "lib/couchrest.rb", "spec/couchrest", "spec/couchrest/core", "spec/couchrest/core/couchrest_spec.rb", "spec/couchrest/core/database_spec.rb", "spec/couchrest/core/design_spec.rb", "spec/couchrest/core/document_spec.rb", "spec/couchrest/core/server_spec.rb", "spec/couchrest/helpers", "spec/couchrest/helpers/pager_spec.rb", "spec/couchrest/helpers/streamer_spec.rb", "spec/couchrest/more", "spec/couchrest/more/casted_extended_doc_spec.rb", "spec/couchrest/more/casted_model_spec.rb", "spec/couchrest/more/extended_doc_attachment_spec.rb", "spec/couchrest/more/extended_doc_spec.rb", "spec/couchrest/more/extended_doc_subclass_spec.rb", "spec/couchrest/more/extended_doc_view_spec.rb", "spec/couchrest/more/property_spec.rb", "spec/fixtures", "spec/fixtures/attachments", "spec/fixtures/attachments/couchdb.png", "spec/fixtures/attachments/README", "spec/fixtures/attachments/test.html", "spec/fixtures/more", "spec/fixtures/more/article.rb", "spec/fixtures/more/card.rb", "spec/fixtures/more/cat.rb", "spec/fixtures/more/course.rb", "spec/fixtures/more/event.rb", "spec/fixtures/more/invoice.rb", "spec/fixtures/more/person.rb", "spec/fixtures/more/question.rb", "spec/fixtures/more/service.rb", "spec/fixtures/views", "spec/fixtures/views/lib.js", "spec/fixtures/views/test_view", "spec/fixtures/views/test_view/lib.js", "spec/fixtures/views/test_view/only-map.js", "spec/fixtures/views/test_view/test-map.js", "spec/fixtures/views/test_view/test-reduce.js", "spec/spec.opts", "spec/spec_helper.rb", "utils/remap.rb", "utils/subset.rb"]
s.has_rdoc = true
s.homepage = %q{http://github.com/jchris/couchrest}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.4}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Lean and RESTful interface to CouchDB.}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rest-client>, [">= 0.5"])

View file

@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
# = CouchDB, close to the metal
module CouchRest
VERSION = '0.33' unless self.const_defined?("VERSION")
VERSION = '0.34' unless self.const_defined?("VERSION")
autoload :Server, 'couchrest/core/server'
autoload :Database, 'couchrest/core/database'

View file

@ -80,6 +80,8 @@ module CouchRest
# 'boolean' type is simply used to generate a property? accessor method
elsif ((property.init_method == 'new') && target == 'boolean')
self[key]
elsif ((property.init_method == 'new') && target == 'Date')
self[key].is_a?(String) ? Date.parse(self[key].dup) : self[key]
else
# Let people use :send as a Time parse arg
klass = ::CouchRest.constantize(target)

View file

@ -224,6 +224,7 @@ module CouchRest
# if the document is not saved properly.
def save!
raise "#{self.inspect} failed to save" unless self.save
true
end
# Deletes the document from the database. Runs the :destroy callbacks.

View file

@ -1,6 +1,7 @@
require File.expand_path("../../../spec_helper", __FILE__)
require File.join(FIXTURE_PATH, 'more', 'article')
require File.join(FIXTURE_PATH, 'more', 'course')
require File.join(FIXTURE_PATH, 'more', 'card')
describe "ExtendedDocument" do
@ -409,6 +410,25 @@ describe "ExtendedDocument" do
it "should set the type" do
@sobj['couchrest-type'].should == 'Basic'
end
describe "save!" do
before(:each) do
@sobj = Card.new(:first_name => "Marcos", :last_name => "Tapajós")
end
it "should return true if save the document" do
@sobj.save!.should == true
end
it "should raise error if don't save the document" do
@sobj.first_name = nil
lambda { @sobj.save!.should == true }.should raise_error(RuntimeError)
end
end
end
describe "saving a model with a unique_id configured" do

View file

@ -132,14 +132,17 @@ describe "ExtendedDocument properties" do
describe "casting" do
describe "cast keys to any type" do
before(:all) do
event_doc = { :subject => "Some event", :occurs_at => Time.now }
event_doc = { :subject => "Some event", :occurs_at => Time.now, :end_date => Date.today }
e = Event.database.save_doc event_doc
@event = Event.get e['id']
end
it "should cast created_at to Time" do
it "should cast occurs_at to Time" do
@event['occurs_at'].should be_an_instance_of(Time)
end
it "should cast end_date to Date" do
@event['end_date'].should be_an_instance_of(Date)
end
end
describe "casting to Float object" do

View file

@ -3,4 +3,7 @@ class Event < CouchRest::ExtendedDocument
property :subject
property :occurs_at, :cast_as => 'Time', :send => 'parse'
property :end_date, :cast_as => 'Date'
end