Module: LogBook::Recorder::ClassMethods

Defined in:
lib/log_book/recorder.rb

Instance Method Summary collapse

Instance Method Details

#has_log_book_records(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/log_book/recorder.rb', line 6

def has_log_book_records(options = {})
  class_attribute :recording_options, instance_writer: false

  self.recording_options = options

  has_many :records, -> { order(created_at: :asc) }, as: :subject, class_name: 'LogBook::Record'
  scope :with_records, -> { joins(:records) }

  on = Array.wrap(options[:on])
  after_create :store_changes if on.empty? || on.include?(:create)
  after_update :store_changes if on.empty? || on.include?(:update)
  after_destroy :store_changes if on.empty? || on.include?(:destroy)

  extend LogBook::Recorder::RecordingClassMethods
  include LogBook::Recorder::RecordingInstanceMethods
end