Module: DirtyDan

Defined in:
lib/dirtydan.rb

Overview

This module provides methods for automation of object dirtyness tracking.

Class Method Summary collapse

Instance Method Summary collapse

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 "            def \#{sym}= (val)\n              mark_dirty() if @\#{sym} != val\n              @\#{sym} = val\n            end\n          THECODE\n        end\n      end\n    end\n    instance_eval do\n      define_method( :attr_accessor ) do |*syms|\n        attr_writer *syms\n        attr_reader *syms\n      end\n    end\n  end\nend\n"

Instance Method Details

#clean_dirtyObject

Clear the dirty mark



37
38
39
# File 'lib/dirtydan.rb', line 37

def clean_dirty
  @dirty = false
end

#hide_dirtyObject

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/dirtydan.rb', line 32

def is_dirty?
  !!@dirty
end

#mark_dirtyObject

Mark an object as dirty



27
28
29
# File 'lib/dirtydan.rb', line 27

def mark_dirty
  @dirty = true
end