Module: PaperTrailScrapbook::VersionHelpers Private

Included in:
Changes, Chapter, JournalEntry
Defined in:
lib/paper_trail_scrapbook/version_helpers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Module VersionHelpers provides methods for extracting common information from a version or PaperTrailScrapbook config

Instance Method Summary collapse

Instance Method Details

#changesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 25

def changes
  Changes.new(version).change_log
end

#configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 29

def config
  PaperTrailScrapbook.config
end

#create?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


17
18
19
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 17

def create?
  event.eql?('create')
end

#destroy?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


21
22
23
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 21

def destroy?
  event.eql?('destroy')
end

#kindObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 37

def kind
  config.events[event] ||
    raise(ArgumentError, "incorrect event:#{event}")
end

#modelObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 9

def model
  version.item_type
end

#model_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 13

def model_id
  version.item_id
end

#whennObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 33

def whenn
  version.created_at.strftime(config.time_format)
end

#whoObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 42

def who
  author = version.version_author
  return config.unknown_whodunnit unless author
  return author unless whodunnit_class

  whodunnit_instance(author)
end

#whodunnit_classObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 50

def whodunnit_class
  config.whodunnit_class
end

#whodunnit_instance(author) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/paper_trail_scrapbook/version_helpers.rb', line 54

def whodunnit_instance(author)
  instance = begin
    whodunnit_class.find(author)
  rescue StandardError
    config.invalid_whodunnit.call(author)
  end

  return instance.to_whodunnit if instance.respond_to?(:to_whodunnit)

  instance.to_s
end