Module: DirtyDan
- Defined in:
- lib/dirtydan.rb
Overview
This module provides methods for automation of object dirtyness tracking.
Class Method Summary collapse
-
.included(mod) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#clean_dirty ⇒ Object
Clear the dirty mark.
-
#hide_dirty ⇒ Object
Hide the dirty tracking variable for dumps, etc.
-
#is_dirty? ⇒ Boolean
Discover if an object is marked dirty.
-
#mark_dirty ⇒ Object
Mark an object as dirty.
Class Method Details
.included(mod) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dirtydan.rb', line 3 def DirtyDan.included(mod) #:nodoc: class << mod instance_eval do define_method( :attr_writer ) do |*syms| syms.each do |sym| class_eval <<-THECODE def #{sym}= (val) mark_dirty() if @#{sym} != val @#{sym} = val end THECODE end end end instance_eval do define_method( :attr_accessor ) do |*syms| attr_writer *syms attr_reader *syms end end end end |
Instance Method Details
#clean_dirty ⇒ Object
Clear the dirty mark
37 38 39 |
# File 'lib/dirtydan.rb', line 37 def clean_dirty @dirty = false end |
#hide_dirty ⇒ Object
Hide the dirty tracking variable for dumps, etc. Has the side effect of clearing the mark.
42 43 44 |
# File 'lib/dirtydan.rb', line 42 def hide_dirty remove_instance_variable(:@dirty) end |
#is_dirty? ⇒ Boolean
Discover if an object is marked dirty
32 33 34 |
# File 'lib/dirtydan.rb', line 32 def is_dirty? !!@dirty end |
#mark_dirty ⇒ Object
Mark an object as dirty
27 28 29 |
# File 'lib/dirtydan.rb', line 27 def mark_dirty @dirty = true end |