Created
August 12, 2013 13:35
-
-
Save cjcolvar/6210840 to your computer and use it in GitHub Desktop.
Example of implementing ActiveModel::Dirty on a ActiveFedora::Base subclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BarHistory2 < ActiveFedora::Base | |
include ActiveModel::Dirty | |
has_metadata 'xmlish', :type=>BarStream2 | |
delegate_to 'xmlish', [:donkey, :cow] | |
after_save :clear_changed_attributes | |
define_attribute_methods [:donkey, :cow] | |
alias_method :_donkey=, :donkey= | |
alias_method :_cow=, :cow= | |
def donkey= val | |
donkey_will_change! unless val == donkey | |
self._donkey = val | |
end | |
def cow= val | |
cow_will_change! unless val == cow | |
self._cow = val | |
end | |
def clear_changed_attributes | |
@previously_changed = changes | |
@changed_attributes.clear | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment