lib/couchrest/model/dirty.rb in couchrest_model-1.1.0.beta3 vs lib/couchrest/model/dirty.rb in couchrest_model-1.1.0.beta4
- old
+ new
@@ -8,41 +8,31 @@
module Model
# This applies to both Model::Base and Model::CastedModel
module Dirty
extend ActiveSupport::Concern
- include CouchRest::Model::CastedBy # needed for base_doc
include ActiveModel::Dirty
included do
# internal dirty setting - overrides global setting.
# this is used to temporarily disable dirty tracking when setting
# attributes directly, for performance reasons.
self.send(:attr_accessor, :disable_dirty)
end
def use_dirty?
- bdoc = base_doc
- bdoc && !bdoc.disable_dirty
+ doc = base_doc
+ doc && !doc.disable_dirty
end
def couchrest_attribute_will_change!(attr)
return if attr.nil? || !use_dirty?
attribute_will_change!(attr)
couchrest_parent_will_change!
end
def couchrest_parent_will_change!
- @casted_by.couchrest_attribute_will_change!(casted_by_attribute) if @casted_by
- end
-
- private
-
- # return the attribute name this object is referenced by in the parent
- def casted_by_attribute
- return @casted_by_attribute if @casted_by_attribute
- attr = @casted_by.attributes
- @casted_by_attribute = attr.keys.detect { |k| attr[k] == self }
+ casted_by.couchrest_attribute_will_change!(casted_by_property.name) if casted_by_property
end
end
end
end