Module: MarkMapper::Plugins::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Included in:
Document
Defined in:
lib/mark_mapper/plugins/dirty.rb

Instance Method Summary collapse

Instance Method Details

#clear_changesObject


25
26
27
28
29
30
31
32
33
# File 'lib/mark_mapper/plugins/dirty.rb', line 25

def clear_changes
  previous = changes
  (block_given? ? yield : true).tap do |result|
    unless result == false #failed validation; nil is OK.
      @previously_changed = previous
      changed_attributes.clear
    end
  end
end

#initializeObject


9
10
11
12
13
14
# File 'lib/mark_mapper/plugins/dirty.rb', line 9

def initialize(*)
  # never register initial id assignment as a change
  # Chaining super into tap breaks implicit block passing in Ruby 1.8
  doc = super
  doc.tap { changed_attributes.delete('_id') }
end

#reloadObject


20
21
22
23
# File 'lib/mark_mapper/plugins/dirty.rb', line 20

def reload(*)
  doc = super
  doc.tap { clear_changes }
end

#saveObject


16
17
18
# File 'lib/mark_mapper/plugins/dirty.rb', line 16

def save(*)
  clear_changes { super }
end