Sha256: bf96b1820520c6a2100d63b351de02fe30697c0477f80f83e87be41d995e3fbe

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module PaperTrailScrapbook
  # Module VersionHelpers provides methods for extracting common information
  # from a version or PaperTrailScrapbook config
  module VersionHelpers
    delegate :event, to: :version

    def model
      version.item_type
    end

    def model_id
      version.item_id
    end

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

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

    def changes
      Changes.new(version).change_log
    end

    def config
      PaperTrailScrapbook.config
    end

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

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

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

      whodunnit_instance(author)
    end

    def whodunnit_class
      config.whodunnit_class
    end

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
paper_trail_scrapbook-0.1.21 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.20 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.19 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.18 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.17 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.16 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.15 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.13 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.12 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.11 lib/paper_trail_scrapbook/version_helpers.rb
paper_trail_scrapbook-0.1.10 lib/paper_trail_scrapbook/version_helpers.rb