Module: TinyDyno::Changeable

Extended by:
ActiveSupport::Concern
Included in:
DocumentComposition
Defined in:
lib/tiny_dyno/changeable.rb

Overview

Defines behaviour for dirty tracking.

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#changedArray<String>

Get the changed attributes for the document.

Examples:

Get the changed attributes.

model.changed

Returns:

  • (Array<String>)

    The changed attributes.

Since:

  • 2.4.0



17
18
19
# File 'lib/tiny_dyno/changeable.rb', line 17

def changed
  changed_attributes.keys.select { |attr| attribute_change(attr) }
end

#changed_attributesHash<String, Object>

Get the attribute changes.

Examples:

Get the attribute changes.

model.changed_attributes

Returns:

  • (Hash<String, Object>)

    The attribute changes.

Since:

  • 2.4.0



29
30
31
# File 'lib/tiny_dyno/changeable.rb', line 29

def changed_attributes
  @changed_attributes ||= {}
end

#changesHash<String, Array<Object, Object> ] The changes.

Get all the changes for the document.

Examples:

Get all the changes.

model.changes

Returns:

  • (Hash<String, Array<Object, Object> ] The changes.)

    Hash<String, Array<Object, Object> ] The changes.

Since:

  • 2.4.0



41
42
43
44
45
46
47
48
49
# File 'lib/tiny_dyno/changeable.rb', line 41

def changes
  _changes = {}
  changed.each do |attr|
    next if attr.nil?
    change = attribute_change(attr)
    _changes[attr] = change
  end
  _changes
end