34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/acts_as_messageable/model.rb', line 34
def acts_as_messageable(options = {})
default_options = {
table_name: 'messages',
class_name: 'ActsAsMessageable::Message',
required: %i[topic body],
dependent: :nullify,
group_messages: false,
search_scope: :search
}
options = default_options.merge(options)
mattr_accessor(:messages_class_name, :group_messages)
has_many :received_messages_relation,
as: :received_messageable,
class_name: options[:class_name],
dependent: options[:dependent]
has_many :sent_messages_relation,
as: :sent_messageable,
class_name: options[:class_name],
dependent: options[:dependent]
self.messages_class_name = options[:class_name].constantize
messages_class_name.has_ancestry
messages_class_name.table_name = options[:table_name]
messages_class_name.initialize_scopes(options[:search_scope])
messages_class_name.required = Array.wrap(options[:required])
messages_class_name.validates_presence_of messages_class_name.required
self.group_messages = options[:group_messages]
include ActsAsMessageable::Model::InstanceMethods
end
|