Merge branch 'master' of github.com:couchrest/couchrest_model

Conflicts:
	lib/couchrest/model/properties.rb
This commit is contained in:
Sam Lown 2011-05-19 00:10:18 +02:00
commit 9754f4633c
6 changed files with 23 additions and 33 deletions

View file

@ -49,6 +49,8 @@ module CouchRest
# * :directly_set_attributes: true when data comes directly from database
# * :database: provide an alternative database
#
# If a block is provided the new model will be passed into the
# block so that it can be populated.
def initialize(doc = {}, options = {})
doc = prepare_all_attributes(doc, options)
# set the instances database, if provided
@ -57,6 +59,8 @@ module CouchRest
unless self['_id'] && self['_rev']
self[self.model_type_key] = self.class.to_s
end
yield self if block_given?
after_initialize if respond_to?(:after_initialize)
end

View file

@ -5,8 +5,8 @@ module CouchRest
extend ActiveSupport::Concern
included do
extlib_inheritable_accessor(:properties) unless self.respond_to?(:properties)
extlib_inheritable_accessor(:properties_by_name) unless self.respond_to?(:properties_by_name)
class_attribute(:properties) unless self.respond_to?(:properties)
class_attribute(:properties_by_name) unless self.respond_to?(:properties_by_name)
self.properties ||= []
self.properties_by_name ||= {}
raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
@ -16,20 +16,6 @@ module CouchRest
Hash[self].reject{|k,v| v.nil?}.as_json(options)
end
# Returns the Class properties
#
# ==== Returns
# Array:: the list of properties for model's class
def properties
self.class.properties
end
# Returns all the class's properties as a Hash where the key is the name
# of the property.
def properties_by_name
self.class.properties_by_name
end
# Returns the Class properties with their values
#
# ==== Returns