Module: MessageTrain::Mixin

Extended by:
ActiveSupport::Concern
Defined in:
lib/message_train/mixin.rb

Overview

Mixin module automatically extended by ActiveRecord::Base

Instance Method Summary collapse

Instance Method Details

#message_train(options = {}) ⇒ Object

Run message_train mixin in your model to enable



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/message_train/mixin.rb', line 7

def message_train(options = {})
  cattr_accessor :message_train_table_sym, :message_train_relationships
  table_sym = table_name.to_sym

  relationships = [options.delete(:only) || [:sender, :recipient]].flatten
  relationships -= [options.delete(:except) || []].flatten

  associations_from_relationships(relationships)

  MessageTrain.configure_table(table_sym, name, options)

  self.message_train_relationships = relationships
  self.message_train_table_sym = table_sym

  extend MessageTrain::ClassMethods
  include MessageTrain::InstanceMethods
end