DirtyDan
Description
A simple module for automation of object dirtiness tracking.
Including the DirtyDan module in a class creates custom attr_writer and attr_accessor methods in the class’s metaclass. When an attribute declared by either of those methods is changed, an instance variable named @dirty will be created and set true.
Installation
gem install dirty_dan
Usage
require 'dirty_dan'
Example
class SimpleExample
include DirtyDan
attr_accessor :somevar
attr_writer :a_write_only_var
def a_custom_var=( val )
.. custom code ..
mark_dirty() # if changed
end
def save
if is_dirty?
hide_dirty() # only needed if using dump or similar
... code saving object state somewhere ...
clean_dirty() # only needed if not using hide_dirty
end
end
end
License
Copyright © 2011 Brian Lee Price
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# The above is the MIT License from <www.opensource.org/licenses/mit-license.php>