Merge branch 'master' of https://github.com/2moro/couchrest_model into 2moro-dirty

Conflicts:
	.gitignore
	lib/couchrest/model/base.rb
	lib/couchrest/model/configuration.rb
	lib/couchrest_model.rb
This commit is contained in:
Sam Lown 2011-04-20 10:47:36 +02:00
commit 1bced3b207
18 changed files with 819 additions and 41 deletions

View file

@ -18,14 +18,17 @@ module CouchRest
include CouchRest::Model::Associations
include CouchRest::Model::Validations
include CouchRest::Model::Designs
include CouchRest::Model::Dirty
include CouchRest::Model::CastedBy
def self.subclasses
@subclasses ||= []
end
def self.inherited(subklass)
super
subklass.send(:include, CouchRest::Model::Properties)
subklass.class_eval <<-EOS, __FILE__, __LINE__ + 1
def self.inherited(subklass)
super
@ -36,7 +39,7 @@ module CouchRest
EOS
subclasses << subklass
end
# Accessors
attr_accessor :casted_by
@ -45,7 +48,7 @@ module CouchRest
# using the provided document hash.
#
# Options supported:
#
#
# * :directly_set_attributes: true when data comes directly from database
# * :database: provide an alternative database
#
@ -59,8 +62,8 @@ module CouchRest
end
after_initialize if respond_to?(:after_initialize)
end
# Temp solution to make the view_by methods available
def self.method_missing(m, *args, &block)
if has_view?(m)
@ -74,24 +77,17 @@ module CouchRest
end
super
end
### instance methods
# Gets a reference to the actual document in the DB
# Calls up to the next document if there is one,
# Otherwise we're at the top and we return self
def base_doc
return self if base_doc?
@casted_by.base_doc
end
# Checks if we're the top document
# (overrides base_doc? in casted_by.rb)
def base_doc?
!@casted_by
end
## Compatibility with ActiveSupport and older frameworks
# Hack so that CouchRest::Document, which descends from Hash,
# doesn't appear to Rails routing as a Hash of options
def is_a?(klass)
@ -103,14 +99,14 @@ module CouchRest
def persisted?
!new?
end
def to_key
new? ? nil : [id]
new? ? nil : [id]
end
alias :to_param :id
alias :new_record? :new?
alias :new_document? :new?
end
end
end
end