Module: HappyMapper::DiffedItem

Defined in:
lib/happymapper/differ.rb

Overview

DiffedItem is an extension which allows tracking changes between two HappyMapper objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#comparedObject Also known as: was

The object this item is being compared to



77
78
79
# File 'lib/happymapper/differ.rb', line 77

def compared
  @compared
end

Class Method Details

.create(item, compared) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/happymapper/differ.rb', line 80

def self.create(item, compared)
  begin
    # if the item can not be cloned, it will raise an exception
    # do not extend objects which can not be cloned
    item.clone
    item.extend(DiffedItem)
  rescue
    # this item is a Float, Nil or other class that can not be extended
    item = UnExtendable.new(item)
    item.extend(DiffedItem)
  end

  item.compared = compared
  item
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
# File 'lib/happymapper/differ.rb', line 96

def changed?
  if self.is_a?(HappyMapper)
    ! changes.empty?
  else
    self != compared
  end
end

#changesObject



104
105
106
# File 'lib/happymapper/differ.rb', line 104

def changes
  @changes ||= ChangeLister.new(self, compared).find_changes
end