now using ActiveModel::Dirty. only writes to database if model.changed?

This commit is contained in:
Andrew Williams 2011-03-01 01:30:41 +10:30
parent 53b052f631
commit 4dbf694e51
14 changed files with 342 additions and 18 deletions

View file

@ -5,6 +5,7 @@
module CouchRest::Model
class CastedArray < Array
include CouchRest::Model::Dirty
attr_accessor :casted_by
attr_accessor :property
@ -14,15 +15,34 @@ module CouchRest::Model
end
def << obj
couchrest_parent_will_change!
super(instantiate_and_cast(obj))
end
def push(obj)
couchrest_parent_will_change!
super(instantiate_and_cast(obj))
end
def pop
couchrest_parent_will_change!
super
end
def shift
couchrest_parent_will_change!
super
end
def unshift(obj)
couchrest_parent_will_change!
super(obj)
end
def []= index, obj
super(index, instantiate_and_cast(obj))
value = instantiate_and_cast(obj)
couchrest_parent_will_change! if value != self[index]
super(index, value)
end
protected