Module: MessageTrain::InstanceMethods::RecipientMethods

Defined in:
lib/message_train/instance_methods.rb

Overview

Included by InstanceMethods when message_train mixin is run, if this is a recipient

Instance Method Summary collapse

Instance Method Details

#all_boxes(*args) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/message_train/instance_methods.rb', line 170

def all_boxes(*args)
  participant = args[0] || self
  divisions = [:in, :sent, :all, :drafts, :trash, :ignored]
  divisions.collect do |division|
    MessageTrain::Box.new(self, division, participant)
  end
end

#box(*args) ⇒ Object



127
128
129
130
131
# File 'lib/message_train/instance_methods.rb', line 127

def box(*args)
  division = args[0] || :in
  participant = args[1] || self
  @box ||= MessageTrain::Box.new(self, division, participant)
end

#collective_boxes(*args) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/message_train/instance_methods.rb', line 133

def collective_boxes(*args)
  division = args[0] || :in
  participant = args[1] || self
  cb_tables = MessageTrain.configuration
                          .collectives_for_recipient_methods
  return {} if cb_tables.empty?
  Hash[cb_tables.map do |key, value|
    box = table_collective_box(key, value, division, participant)
    [key, box]
  end]
end

#collective_boxes_show_flagsObject



151
152
153
154
155
156
157
158
# File 'lib/message_train/instance_methods.rb', line 151

def collective_boxes_show_flags
  Hash[collective_boxes.map do |key, collectives|
    flag = collectives.select do |collective_box|
      collective_box.parent.allows_access_by?(self)
    end.any?
    [key, flag]
  end]
end

#collective_boxes_unread_countsObject



145
146
147
148
149
# File 'lib/message_train/instance_methods.rb', line 145

def collective_boxes_unread_counts
  Hash[collective_boxes.map do |key, collectives|
    [key, collectives.collect(&:unread_count).sum]
  end]
end

#message_train_nameObject



178
179
180
# File 'lib/message_train/instance_methods.rb', line 178

def message_train_name
  send(self.class.name_column)
end

#message_train_slugObject



182
183
184
# File 'lib/message_train/instance_methods.rb', line 182

def message_train_slug
  send(self.class.slug_column)
end

#table_collective_box(table_sym, collectives_method, division, participant) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/message_train/instance_methods.rb', line 160

def table_collective_box(
  table_sym, collectives_method, division, participant
)
  model = MessageTrain.configuration
                      .recipient_tables[table_sym]
                      .constantize
  collectives = model.send(collectives_method, participant)
  collectives.map { |x| x.box(division, participant) }.compact
end