Sha256: 005cecf01b5bde8c9ec467e7ac7737e1298693aa16fdbb4ddd4631e66ced158d

Contents?: true

Size: 859 Bytes

Versions: 4

Compression:

Stored size: 859 Bytes

Contents

module LogBook
  class Record < ActiveRecord::Base
    self.table_name = LogBook.config.records_table_name

    belongs_to :subject, polymorphic: true
    belongs_to :author, polymorphic: true
    belongs_to :parent, polymorphic: true

    before_create :set_request_uuid

    def self.collection_cache_key(collection = all, timestamp_column = :created_at)
      super(collection, timestamp_column)
    end

    def subject_key
      subject.class.table_name
    end

    def changes_to_record?
      !(record_changes == {} && skip_if_empty_actions.include?(action))
    end

    private

    def set_request_uuid
      self.request_uuid ||= LogBook.store[:request_uuid] || SecureRandom.uuid
    end

    def skip_if_empty_actions
      (subject.recording_options[:skip_if_empty_actions] || LogBook.config.skip_if_empty_actions).map(&:to_s)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_log_book-1.0.0 lib/log_book/record.rb
rails_log_book-0.3.0 lib/log_book/record.rb
rails_log_book-0.2.0 lib/log_book/record.rb
rails_log_book-0.1.0 lib/log_book/record.rb