Skip to content

Instantly share code, notes, and snippets.

@cjcolvar
Created August 12, 2013 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjcolvar/6210840 to your computer and use it in GitHub Desktop.
Save cjcolvar/6210840 to your computer and use it in GitHub Desktop.
Example of implementing ActiveModel::Dirty on a ActiveFedora::Base subclass
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