d333133319
* ActiveModel::Dirty ** Basic support for dirty tracking ** It does not bubble up any changes to casted models currently * ActiveModel::AttributeMethods ** Attributes are now read and written through ActiveModel ** This also allows you to add your own attribute methods with prefix suffix and affix names. For more information check out ActiveModel::AttributeMethods::ClassMethods
45 lines
1 KiB
Ruby
45 lines
1 KiB
Ruby
# encoding: utf-8
|
|
require 'active_model/dirty'
|
|
|
|
module CouchRest #:nodoc:
|
|
module Model #:nodoc:
|
|
|
|
# Dirty Tracking support via ActiveModel
|
|
# mixin methods include:
|
|
# #changed?, #changed, #changes, #previous_changes
|
|
# #<attribute>_changed?, #<attribute>_change,
|
|
# #reset_<attribute>!, #<attribute>_will_change!,
|
|
# and #<attribute>_was
|
|
#
|
|
# Please see the specs or the documentation of
|
|
# ActiveModel::Dirty for more information
|
|
module Dirty
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
include ActiveModel::Dirty
|
|
after_save :clear_changed_attributes
|
|
end
|
|
|
|
def initialize(*args)
|
|
super
|
|
@changed_attributes.clear if @changed_attributes
|
|
end
|
|
|
|
def write_attribute(name, value)
|
|
meth = :"#{name}_will_change!"
|
|
__send__ meth if respond_to? meth
|
|
super
|
|
end
|
|
|
|
private
|
|
|
|
def clear_changed_attributes
|
|
@previously_changed = changes
|
|
@changed_attributes.clear
|
|
true
|
|
end
|
|
end
|
|
end
|
|
end
|