Module: DraftPunk::Model::DraftDiffInstanceMethods

Defined in:
lib/draft_diff_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#draft_diff(include_associations: false, parent_object_fk: nil, include_all_attributes: false, include_diff: false, diff_format: :html, recursed: false) ⇒ Hash

Return the differences between the live and draft object.

If include_associations is true, it will return the diff for all child associations, recursively until it gets to the bottom of your draft tree. This only works for associations which have the approved_version_id column

Parameters:

  • include_associations (Boolean) (defaults to: false)

    include diff for child objects, recursive (possibly down to grandchildren and beyond)

  • include_all_attributes (Boolean) (defaults to: false)

    return all attributes in the results, including those which have not changed

  • include_diff (Boolean) (defaults to: false)

    include an html formatted diff of changes between the live and draft, for each attribute

  • diff_format (Symbol) (defaults to: :html)

    format the diff output per the options available in differ (:html, :ascii, :color)

Returns:

  • (Hash)


15
16
17
18
# File 'lib/draft_diff_instance_methods.rb', line 15

def draft_diff(include_associations: false, parent_object_fk: nil, include_all_attributes: false, include_diff: false, diff_format: :html, recursed: false)
  draft_obj = recursed ? draft : get_draft # get_draft will create missing drafts. Based on the logic, this should only happen when you *first* call draft_diff
  get_object_changes(self, draft_obj, include_associations, parent_object_fk, include_all_attributes, include_diff, diff_format)
end