added database.bulk_delete as an alias for #bulk_save, added support for Model.by_view_name in ExtendedDoc and bumped the version to 0.13.3

This commit is contained in:
Matt Aimonetti 2009-02-17 00:36:11 -08:00
parent 3c01875ce5
commit c4cce18389
8 changed files with 20 additions and 10 deletions

View file

@ -2,7 +2,7 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{couchrest} s.name = %q{couchrest}
s.version = "0.13.2" s.version = "0.13.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti"] s.authors = ["J. Chris Anderson", "Matt Aimonetti"]

View file

@ -27,7 +27,7 @@ require 'couchrest/monkeypatches'
# = CouchDB, close to the metal # = CouchDB, close to the metal
module CouchRest module CouchRest
VERSION = '0.13.2' VERSION = '0.13.3'
autoload :Server, 'couchrest/core/server' autoload :Server, 'couchrest/core/server'
autoload :Database, 'couchrest/core/database' autoload :Database, 'couchrest/core/database'

View file

@ -90,9 +90,7 @@ module CouchRest
def fetch_attachment(doc, name) def fetch_attachment(doc, name)
# slug = escape_docid(docid) # slug = escape_docid(docid)
# name = CGI.escape(name) # name = CGI.escape(name)
uri = uri_for_attachment(doc, name) uri = uri_for_attachment(doc, name)
RestClient.get uri RestClient.get uri
# "#{@uri}/#{slug}/#{name}" # "#{@uri}/#{slug}/#{name}"
end end
@ -177,6 +175,7 @@ module CouchRest
end end
CouchRest.post "#{@uri}/_bulk_docs", {:docs => docs} CouchRest.post "#{@uri}/_bulk_docs", {:docs => docs}
end end
alias :bulk_delete :bulk_save
# DELETE the document from CouchDB that has the given <tt>_id</tt> and # DELETE the document from CouchDB that has the given <tt>_id</tt> and
# <tt>_rev</tt>. # <tt>_rev</tt>.

View file

@ -16,7 +16,7 @@ module CouchRest
unless design_doc_fresh unless design_doc_fresh
refresh_design_doc refresh_design_doc
end end
view :all, opts, &block view(:all, opts, &block)
end end
# Load the first document that have the "couchrest-type" field equal to # Load the first document that have the "couchrest-type" field equal to

View file

@ -65,7 +65,7 @@ module CouchRest
module ClassMethods module ClassMethods
def property(name, options={}) def property(name, options={})
define_property(name, options) unless properties.map{|p| p.name}.include?(name.to_s) define_property(name, options) unless self.properties.map{|p| p.name}.include?(name.to_s)
end end
protected protected

View file

@ -95,7 +95,7 @@ module CouchRest
end end
# Dispatches to any named view. # Dispatches to any named view.
def view name, query={}, &block def view(name, query={}, &block)
unless design_doc_fresh unless design_doc_fresh
refresh_design_doc refresh_design_doc
end end
@ -128,9 +128,9 @@ module CouchRest
private private
def fetch_view_with_docs name, opts, raw=false, &block def fetch_view_with_docs(name, opts, raw=false, &block)
if raw if raw
fetch_view name, opts, &block fetch_view(name, opts, &block)
else else
begin begin
view = fetch_view name, opts.merge({:include_docs => true}), &block view = fetch_view name, opts.merge({:include_docs => true}), &block
@ -138,7 +138,7 @@ module CouchRest
rescue rescue
# fallback for old versions of couchdb that don't # fallback for old versions of couchdb that don't
# have include_docs support # have include_docs support
view = fetch_view name, opts, &block view = fetch_view(name, opts, &block)
view['rows'].collect{|r|new(database.get(r['id']))} if view['rows'] view['rows'].collect{|r|new(database.get(r['id']))} if view['rows']
end end
end end

View file

@ -74,6 +74,16 @@ module CouchRest
end end
end end
# Temp solution to make the view_by methods available
def self.method_missing(m, *args)
if has_view?(m)
query = args.shift || {}
view(m, query, *args)
else
super
end
end
### instance methods ### instance methods
# Returns the Class properties # Returns the Class properties

View file

@ -72,6 +72,7 @@ describe CouchRest::CastedModel do
before(:each) do before(:each) do
@obj = DummyModel.new(:casted_attribute => {:name => 'whatever'}) @obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
@obj.save.should be_true @obj.save.should be_true
@obj = DummyModel.get(@obj.id)
end end
it "should be able to load with the casted models" do it "should be able to load with the casted models" do