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



176
177
178
179
180
181
182
# File 'lib/message_train/instance_methods.rb', line 176

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
# File 'lib/message_train/instance_methods.rb', line 133

def collective_boxes(*args)
  division = args[0] || :in
  participant = args[1] || self
  @collective_boxes ||= {}
  @collective_boxes[[division, participant]] ||=
    compute_collective_boxes(division, participant)
end

#collective_boxes_show_flagsObject



147
148
149
150
151
152
153
154
# File 'lib/message_train/instance_methods.rb', line 147

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



141
142
143
144
145
# File 'lib/message_train/instance_methods.rb', line 141

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

#compute_collective_boxes(division, participant) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/message_train/instance_methods.rb', line 166

def compute_collective_boxes(division, participant)
  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

#message_train_nameObject



184
185
186
# File 'lib/message_train/instance_methods.rb', line 184

def message_train_name
  send(self.class.name_column)
end

#message_train_slugObject



188
189
190
# File 'lib/message_train/instance_methods.rb', line 188

def message_train_slug
  send(self.class.slug_column)
end

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



156
157
158
159
160
161
162
163
164
# File 'lib/message_train/instance_methods.rb', line 156

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