Sha256: 0db3180f6d7c2369708f8a4b5199bdcaf7cc6bf3f5a32d01fa3af02ce0456f6b

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

module LogBook
  module ControllerRecord
    extend ActiveSupport::Concern

    included do
      before_action :enable_recording
      after_action :save_records
    end

    def enable_recording
      action = "#{controller_name}##{action_name}"
      author = current_author
      request_uuid = try(:request).try(:uuid) || SecureRandom.hex
      LogBook::Store.tree = LogBook::Tree.new(action: action, author: author, request_uuid: request_uuid)
      LogBook.enable_recording
    end

    def save_records
      LogBook::SaveRecords.call
    end

    def current_author
      raise NotImplementedError unless respond_to?(LogBook.config.author_method, true)

      send(LogBook.config.author_method)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_log_book-2.4.0 lib/log_book/controller_record.rb
rails_log_book-2.3.0 lib/log_book/controller_record.rb
rails_log_book-2.2.0 lib/log_book/controller_record.rb
rails_log_book-2.1.0 lib/log_book/controller_record.rb