Renaming casted model to embeddable and preparing for 1.1.0 launch@
This commit is contained in:
parent
05ed7b127f
commit
8efa5208da
13 changed files with 51 additions and 33 deletions
|
@ -47,8 +47,8 @@ module CouchRest
|
|||
#
|
||||
# Options supported:
|
||||
#
|
||||
# * :directly_set_attributes: true when data comes directly from database
|
||||
# * :database: provide an alternative database
|
||||
# * :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.
|
||||
|
@ -64,6 +64,7 @@ module CouchRest
|
|||
yield self if block_given?
|
||||
|
||||
after_initialize if respond_to?(:after_initialize)
|
||||
run_callbacks(:initialize) { self }
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module CouchRest::Model
|
||||
module CastedModel
|
||||
module Embeddable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
@ -26,6 +26,7 @@ module CouchRest::Model
|
|||
def initialize(keys = {}, options = {})
|
||||
super()
|
||||
prepare_all_attributes(keys, options)
|
||||
run_callbacks(:initialize) { self }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -61,6 +62,14 @@ module CouchRest::Model
|
|||
end
|
||||
alias :attributes= :update_attributes_without_saving
|
||||
|
||||
end # End Embeddable
|
||||
|
||||
# Provide backwards compatability with previous versions (pre 1.1.0)
|
||||
module CastedModel
|
||||
extend ActiveSupport::Concern
|
||||
included do
|
||||
include CouchRest::Model::Embeddable
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -167,7 +167,7 @@ module CouchRest
|
|||
type = options.delete(:type) || options.delete(:cast_as)
|
||||
if block_given?
|
||||
type = Class.new do
|
||||
include CastedModel
|
||||
include Embeddable
|
||||
end
|
||||
if block.arity == 1 # Traditional, with options
|
||||
type.class_eval { yield type }
|
||||
|
|
|
@ -45,7 +45,7 @@ module CouchRest::Model
|
|||
|
||||
# Cast an individual value, not an array
|
||||
def cast_value(parent, value)
|
||||
raise "An array inside an array cannot be casted, use CastedModel" if value.is_a?(Array)
|
||||
raise "An array inside an array cannot be casted, use Embeddable module" if value.is_a?(Array)
|
||||
value = typecast_value(value, self)
|
||||
associate_casted_value_to_parent(parent, value)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue