message_train 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.ruby-gemset +1 -1
- data/.scss-lint.yml +7 -0
- data/.simplecov +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +6 -2
- data/LICENSE.txt +2 -2
- data/README.rdoc +5 -5
- data/Rakefile +22 -21
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +1 -1
- data/app/assets/stylesheets/message_train.scss +29 -19
- data/app/controllers/concerns/message_train_support.rb +41 -37
- data/app/controllers/message_train/application_controller.rb +1 -0
- data/app/controllers/message_train/boxes_controller.rb +5 -4
- data/app/controllers/message_train/conversations_controller.rb +8 -7
- data/app/controllers/message_train/messages_controller.rb +25 -22
- data/app/controllers/message_train/participants_controller.rb +27 -23
- data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
- data/app/helpers/message_train/application_helper.rb +6 -8
- data/app/helpers/message_train/attachments_helper.rb +12 -4
- data/app/helpers/message_train/boxes_helper.rb +38 -11
- data/app/helpers/message_train/collectives_helper.rb +38 -12
- data/app/helpers/message_train/conversations_helper.rb +43 -35
- data/app/helpers/message_train/messages_helper.rb +32 -25
- data/app/mailers/message_train/application_mailer.rb +7 -4
- data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
- data/app/mailers/message_train/receipt_mailer.rb +14 -4
- data/app/models/message_train/attachment.rb +41 -25
- data/app/models/message_train/box.rb +159 -122
- data/app/models/message_train/conversation.rb +84 -41
- data/app/models/message_train/ignore.rb +8 -2
- data/app/models/message_train/message.rb +72 -42
- data/app/models/message_train/receipt.rb +30 -17
- data/app/models/message_train/unsubscribe.rb +1 -0
- data/app/views/application/404.html.haml +1 -1
- data/app/views/layouts/mailer.html.haml +2 -2
- data/app/views/layouts/mailer.text.haml +1 -1
- data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
- data/app/views/message_train/application/_widget.html.haml +1 -1
- data/app/views/message_train/application/results.json.jbuilder +1 -1
- data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/boxes/_list_item.html.haml +1 -1
- data/app/views/message_train/boxes/show.html.haml +1 -1
- data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/collectives/_list_item.html.haml +1 -1
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
- data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/show.html.haml +2 -2
- data/app/views/message_train/conversations/show.json.jbuilder +5 -1
- data/app/views/message_train/messages/_form.html.haml +1 -1
- data/app/views/message_train/messages/_message.html.haml +6 -6
- data/app/views/message_train/messages/_toggle.html.haml +1 -1
- data/app/views/message_train/messages/show.json.jbuilder +5 -1
- data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
- data/app/views/message_train/participants/index.json.jbuilder +1 -1
- data/app/views/message_train/participants/show.json.jbuilder +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
- data/app/views/message_train/unsubscribes/index.html.haml +1 -1
- data/config/environment.rb +1 -1
- data/config/initializers/date_time.rb +2 -2
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +37 -15
- data/lib/generators/message_train/install/install_generator.rb +26 -11
- data/lib/generators/message_train/install/templates/initializer.rb +0 -2
- data/lib/generators/message_train/utils.rb +11 -4
- data/lib/message_train/configuration.rb +4 -5
- data/lib/message_train/engine.rb +1 -7
- data/lib/message_train/localization.rb +14 -18
- data/lib/message_train/mixin.rb +211 -150
- data/lib/message_train/version.rb +1 -0
- data/lib/message_train.rb +7 -6
- data/message_train.gemspec +24 -11
- data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
- data/spec/controllers/message_train/concerns_spec.rb +17 -13
- data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
- data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
- data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
- data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
- data/spec/dummy/app/controllers/application_controller.rb +7 -7
- data/spec/dummy/app/models/group.rb +1 -1
- data/spec/dummy/app/models/role.rb +11 -7
- data/spec/dummy/app/models/user.rb +6 -5
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
- data/spec/dummy/app/views/layouts/application.html.haml +1 -1
- data/spec/dummy/app/views/pages/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +23 -17
- data/spec/dummy/config/environments/development.rb +5 -4
- data/spec/dummy/config/environments/production.rb +10 -6
- data/spec/dummy/config/environments/test.rb +4 -3
- data/spec/dummy/config/initializers/assets.rb +2 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
- data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
- data/spec/dummy/config/initializers/devise.rb +63 -44
- data/spec/dummy/config/initializers/high_voltage.rb +1 -1
- data/spec/dummy/config/initializers/message_train.rb +5 -2
- data/spec/dummy/config/initializers/mime_types.rb +1 -1
- data/spec/dummy/config/initializers/paperclip.rb +5 -2
- data/spec/dummy/config/initializers/rolify.rb +3 -2
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/config/settings.yml +1 -1
- data/spec/dummy/db/schema.rb +98 -98
- data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
- data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
- data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
- data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
- data/spec/dummy/db/seeds/users.seeds.rb +47 -42
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/attachment.rb +6 -2
- data/spec/factories/group.rb +1 -4
- data/spec/factories/message.rb +29 -23
- data/spec/factories/user.rb +6 -4
- data/spec/features/boxes_spec.rb +76 -24
- data/spec/features/conversations_spec.rb +19 -7
- data/spec/features/messages_spec.rb +24 -5
- data/spec/features/unsubscribes_spec.rb +36 -9
- data/spec/helpers/message_train/application_helper_spec.rb +1 -1
- data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
- data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
- data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
- data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
- data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
- data/spec/message_train_spec.rb +3 -2
- data/spec/models/group_spec.rb +12 -9
- data/spec/models/message_train/attachment_spec.rb +33 -30
- data/spec/models/message_train/box_spec.rb +243 -60
- data/spec/models/message_train/conversation_spec.rb +16 -12
- data/spec/models/message_train/ignore_spec.rb +3 -1
- data/spec/models/message_train/message_spec.rb +22 -7
- data/spec/models/message_train/receipt_spec.rb +14 -4
- data/spec/models/role_spec.rb +10 -6
- data/spec/models/user_spec.rb +74 -22
- data/spec/rails_helper.rb +9 -4
- data/spec/spec_helper.rb +6 -54
- data/spec/support/controller_behaviors.rb +8 -5
- data/spec/support/controller_macros.rb +2 -2
- data/spec/support/factory_girl.rb +1 -1
- data/spec/support/feature_behaviors.rb +42 -13
- data/spec/support/loaded_site/attachments.rb +8 -0
- data/spec/support/loaded_site/conversations.rb +73 -0
- data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
- data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
- data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
- data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
- data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
- data/spec/support/shared_connection.rb +8 -6
- data/spec/support/utilities.rb +10 -10
- metadata +67 -10
- data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
- data/spec/support/attachments.rb +0 -4
- data/spec/support/conversations.rb +0 -23
data/lib/message_train/mixin.rb
CHANGED
@@ -1,22 +1,33 @@
|
|
1
1
|
module MessageTrain
|
2
|
+
# Mixin for including in a model
|
2
3
|
module Mixin
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
class_methods do
|
5
6
|
def message_train(options = {})
|
6
7
|
table_sym = table_name.to_sym
|
7
8
|
|
8
|
-
relationships =
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
relationships = if options[:only]
|
10
|
+
[options[:only]].flatten
|
11
|
+
else
|
12
|
+
[:sender, :recipient]
|
13
|
+
end
|
14
|
+
options[:except] && relationships -= [options[:except]].flatten
|
12
15
|
|
13
16
|
if relationships.include? :sender
|
14
17
|
has_many :messages, as: :sender, class_name: 'MessageTrain::Message'
|
15
18
|
end
|
16
19
|
|
17
20
|
if relationships.include? :recipient
|
18
|
-
has_many
|
19
|
-
|
21
|
+
has_many(
|
22
|
+
:receipts,
|
23
|
+
as: :recipient,
|
24
|
+
class_name: 'MessageTrain::Receipt'
|
25
|
+
)
|
26
|
+
has_many(
|
27
|
+
:unsubscribes,
|
28
|
+
as: :recipient,
|
29
|
+
class_name: 'MessageTrain::Unsubscribe'
|
30
|
+
)
|
20
31
|
end
|
21
32
|
|
22
33
|
MessageTrain.configure(MessageTrain.configuration) do |config|
|
@@ -29,7 +40,9 @@ module MessageTrain
|
|
29
40
|
end
|
30
41
|
|
31
42
|
if options[:address_book_method].present?
|
32
|
-
config.address_book_methods[table_sym] = options[
|
43
|
+
config.address_book_methods[table_sym] = options[
|
44
|
+
:address_book_method
|
45
|
+
]
|
33
46
|
end
|
34
47
|
|
35
48
|
if relationships.include? :recipient
|
@@ -37,7 +50,9 @@ module MessageTrain
|
|
37
50
|
end
|
38
51
|
|
39
52
|
if options[:collectives_for_recipient].present?
|
40
|
-
config.collectives_for_recipient_methods[table_sym] = options[
|
53
|
+
config.collectives_for_recipient_methods[table_sym] = options[
|
54
|
+
:collectives_for_recipient
|
55
|
+
]
|
41
56
|
end
|
42
57
|
|
43
58
|
if options[:valid_senders].present?
|
@@ -45,166 +60,203 @@ module MessageTrain
|
|
45
60
|
end
|
46
61
|
|
47
62
|
if options[:valid_recipients].present?
|
48
|
-
config.valid_recipients_methods[table_sym] = options[
|
63
|
+
config.valid_recipients_methods[table_sym] = options[
|
64
|
+
:valid_recipients
|
65
|
+
]
|
49
66
|
end
|
50
67
|
end
|
51
68
|
|
52
|
-
send(:define_method, :slug_part)
|
69
|
+
send(:define_method, :slug_part) do
|
53
70
|
send(MessageTrain.configuration.slug_columns[table_sym] || :slug)
|
54
|
-
|
71
|
+
end
|
55
72
|
|
56
|
-
send(:define_method, :path_part)
|
57
|
-
if MessageTrain.configuration.valid_senders_methods[
|
73
|
+
send(:define_method, :path_part) do
|
74
|
+
if MessageTrain.configuration.valid_senders_methods[
|
75
|
+
table_sym
|
76
|
+
].present?
|
58
77
|
# This must mean it's a collective
|
59
78
|
"#{self.class.table_name}:#{slug_part}"
|
60
79
|
end
|
61
|
-
|
80
|
+
end
|
62
81
|
|
63
|
-
send(:define_method, :valid_senders)
|
64
|
-
|
65
|
-
|
66
|
-
|
82
|
+
send(:define_method, :valid_senders) do
|
83
|
+
send(
|
84
|
+
MessageTrain.configuration.valid_senders_methods[
|
85
|
+
self.class.table_name.to_sym
|
86
|
+
] || :self_collection
|
87
|
+
)
|
88
|
+
end
|
67
89
|
|
68
|
-
send(:define_method, :allows_sending_by?)
|
90
|
+
send(:define_method, :allows_sending_by?) do |sender|
|
69
91
|
valid_senders.include? sender
|
70
|
-
|
92
|
+
end
|
71
93
|
|
72
|
-
send(:define_method, :valid_recipients)
|
73
|
-
|
74
|
-
|
75
|
-
|
94
|
+
send(:define_method, :valid_recipients) do
|
95
|
+
send(
|
96
|
+
MessageTrain.configuration.valid_recipients_methods[
|
97
|
+
self.class.table_name.to_sym
|
98
|
+
] || :self_collection
|
99
|
+
)
|
100
|
+
end
|
76
101
|
|
77
|
-
send(:define_method, :allows_receiving_by?)
|
78
|
-
if valid_recipients.nil?
|
102
|
+
send(:define_method, :allows_receiving_by?) do |recipient|
|
103
|
+
if valid_recipients.nil? || valid_recipients.empty?
|
79
104
|
false
|
80
105
|
else
|
81
106
|
valid_recipients.include? recipient
|
82
107
|
end
|
83
|
-
|
108
|
+
end
|
84
109
|
|
85
|
-
send(:define_method, :self_collection)
|
110
|
+
send(:define_method, :self_collection) do
|
111
|
+
# This turns a single record into an active record collection.
|
86
112
|
model = self.class
|
87
|
-
model.where(id:
|
88
|
-
|
113
|
+
model.where(id: id)
|
114
|
+
end
|
89
115
|
|
90
116
|
if relationships.include? :recipient
|
91
|
-
send(:define_method, :box)
|
117
|
+
send(:define_method, :box) do |*args|
|
92
118
|
case args.count
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
119
|
+
when 0
|
120
|
+
division = :in
|
121
|
+
participant = self
|
122
|
+
when 1
|
123
|
+
division = args[0] || :in
|
124
|
+
participant = self
|
125
|
+
when 2
|
126
|
+
division = args[0] || :in
|
127
|
+
participant = args[1] || self
|
128
|
+
else
|
129
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
130
|
+
right: '0..2',
|
131
|
+
wrong: args.count.to_s,
|
132
|
+
thing: self.class.name
|
133
|
+
)
|
104
134
|
end
|
105
135
|
@box ||= MessageTrain::Box.new(self, division, participant)
|
106
|
-
|
136
|
+
end
|
107
137
|
|
108
|
-
send(:define_method, :collective_boxes)
|
138
|
+
send(:define_method, :collective_boxes) do |*args|
|
109
139
|
case args.count
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
140
|
+
when 0
|
141
|
+
division = :in
|
142
|
+
participant = self
|
143
|
+
when 1
|
144
|
+
division = args[0] || :in
|
145
|
+
participant = self
|
146
|
+
when 2
|
147
|
+
division = args[0] || :in
|
148
|
+
participant = args[1] || self
|
149
|
+
else # Treat all but the division as a hash of options
|
150
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
151
|
+
right: '0..2',
|
152
|
+
wrong: args.count.to_s,
|
153
|
+
thing: self.class.name
|
154
|
+
)
|
121
155
|
end
|
122
|
-
|
156
|
+
cb_tables = MessageTrain.configuration
|
157
|
+
.collectives_for_recipient_methods
|
123
158
|
collective_boxes = {}
|
124
|
-
unless
|
125
|
-
|
126
|
-
class_name = MessageTrain.configuration
|
159
|
+
unless cb_tables.empty?
|
160
|
+
cb_tables.each do |my_table_symbol, collectives_method|
|
161
|
+
class_name = MessageTrain.configuration
|
162
|
+
.recipient_tables[my_table_symbol]
|
127
163
|
model = class_name.constantize
|
128
164
|
collectives = model.send(collectives_method, participant)
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
165
|
+
next if collectives.empty?
|
166
|
+
collectives.each do |collective|
|
167
|
+
collective_boxes[my_table_symbol] ||= []
|
168
|
+
collective_boxes[my_table_symbol] << collective.box(
|
169
|
+
division,
|
170
|
+
participant
|
171
|
+
)
|
134
172
|
end
|
135
173
|
end
|
136
174
|
end
|
137
175
|
collective_boxes
|
138
|
-
|
176
|
+
end
|
139
177
|
|
140
|
-
send(:define_method, :all_boxes)
|
178
|
+
send(:define_method, :all_boxes) do |*args|
|
141
179
|
case args.count
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
180
|
+
when 0
|
181
|
+
participant = self
|
182
|
+
when 1
|
183
|
+
participant = args[0] || self
|
184
|
+
else # Treat all but the division as a hash of options
|
185
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
186
|
+
right: '0..1',
|
187
|
+
wrong: args.count.to_s,
|
188
|
+
thing: self.class.name
|
189
|
+
)
|
148
190
|
end
|
149
191
|
divisions = [:in, :sent, :all, :drafts, :trash, :ignored]
|
150
|
-
divisions.collect
|
151
|
-
|
192
|
+
divisions.collect do |division|
|
193
|
+
MessageTrain::Box.new(self, division, participant)
|
194
|
+
end
|
195
|
+
end
|
152
196
|
end
|
153
197
|
|
154
|
-
send(:define_method, :conversations)
|
198
|
+
send(:define_method, :conversations) do |*args|
|
155
199
|
case args.count
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
200
|
+
when 0
|
201
|
+
division = :in
|
202
|
+
participant = self
|
203
|
+
when 1
|
204
|
+
division = args[0] || :in
|
205
|
+
participant = self
|
206
|
+
when 2
|
207
|
+
division = args[0] || :in
|
208
|
+
participant = args[1] || self
|
209
|
+
else # Treat all but the division as a hash of options
|
210
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
211
|
+
right: '0..2',
|
212
|
+
wrong: args.count.to_s,
|
213
|
+
thing: self.class.name
|
214
|
+
)
|
167
215
|
end
|
168
|
-
my_conversations = MessageTrain::Conversation.with_messages_through(
|
216
|
+
my_conversations = MessageTrain::Conversation.with_messages_through(
|
217
|
+
self
|
218
|
+
)
|
169
219
|
case division
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
else
|
183
|
-
nil
|
220
|
+
when :in
|
221
|
+
my_conversations.with_untrashed_to(participant)
|
222
|
+
when :sent
|
223
|
+
my_conversations.with_untrashed_by(participant)
|
224
|
+
when :all
|
225
|
+
my_conversations.with_untrashed_for(participant)
|
226
|
+
when :drafts
|
227
|
+
my_conversations.with_drafts_by(participant)
|
228
|
+
when :trash
|
229
|
+
my_conversations.with_trashed_for(participant)
|
230
|
+
when :ignored
|
231
|
+
my_conversations.ignored(participant)
|
184
232
|
end
|
185
|
-
|
233
|
+
end
|
186
234
|
|
187
|
-
send(:define_method, :boxes_for_participant)
|
235
|
+
send(:define_method, :boxes_for_participant) do |participant|
|
188
236
|
original_order = [:in, :sent, :all, :drafts, :trash, :ignored]
|
189
237
|
divisions = [:all, :trash]
|
190
|
-
if
|
238
|
+
if respond_to?(:messages) || allows_sending_by?(participant)
|
191
239
|
divisions += [:sent, :drafts]
|
192
240
|
end
|
193
|
-
|
194
|
-
divisions += [:in, :ignored]
|
195
|
-
end
|
241
|
+
allows_receiving_by?(participant) && divisions += [:in, :ignored]
|
196
242
|
divisions.sort_by! { |x| original_order.index x }
|
197
|
-
divisions.collect
|
198
|
-
|
243
|
+
divisions.collect do |division|
|
244
|
+
MessageTrain::Box.new(self, division, participant)
|
245
|
+
end
|
246
|
+
end
|
199
247
|
|
200
|
-
send(:define_method, :all_conversations)
|
248
|
+
send(:define_method, :all_conversations) do |*args|
|
201
249
|
case args.count
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
250
|
+
when 0
|
251
|
+
participant = self
|
252
|
+
when 1
|
253
|
+
participant = args[0] || self
|
254
|
+
else # Treat all but the division as a hash of options
|
255
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
256
|
+
right: '0..1',
|
257
|
+
wrong: args.count.to_s,
|
258
|
+
thing: self.class.name
|
259
|
+
)
|
208
260
|
end
|
209
261
|
results = MessageTrain::Conversation.with_messages_through(self)
|
210
262
|
if results.empty?
|
@@ -212,16 +264,20 @@ module MessageTrain
|
|
212
264
|
else
|
213
265
|
results.with_messages_for(participant)
|
214
266
|
end
|
215
|
-
|
267
|
+
end
|
216
268
|
|
217
|
-
send(:define_method, :all_messages)
|
269
|
+
send(:define_method, :all_messages) do |*args|
|
218
270
|
case args.count
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
271
|
+
when 0
|
272
|
+
participant = self
|
273
|
+
when 1
|
274
|
+
participant = args[0] || self
|
275
|
+
else # Treat all but the division as a hash of options
|
276
|
+
raise :wrong_number_of_arguments_right_wrong.l(
|
277
|
+
right: '0..1',
|
278
|
+
wrong: args.count.to_s,
|
279
|
+
thing: self.class.name
|
280
|
+
)
|
225
281
|
end
|
226
282
|
results = MessageTrain::Message.with_receipts_through(self)
|
227
283
|
if results.empty?
|
@@ -229,46 +285,51 @@ module MessageTrain
|
|
229
285
|
else
|
230
286
|
results.with_receipts_for(participant)
|
231
287
|
end
|
232
|
-
|
288
|
+
end
|
233
289
|
|
234
|
-
send(:define_method, :unsubscribed_from_all?)
|
290
|
+
send(:define_method, :unsubscribed_from_all?) do
|
235
291
|
unsubscribes.where(from: nil).exists?
|
236
|
-
|
292
|
+
end
|
237
293
|
|
238
|
-
send(:define_method, :unsubscribed_from?)
|
239
|
-
unsubscribed_from_all?
|
240
|
-
|
294
|
+
send(:define_method, :unsubscribed_from?) do |from|
|
295
|
+
unsubscribed_from_all? || unsubscribes.where(from: from).exists?
|
296
|
+
end
|
241
297
|
|
242
|
-
send(:define_method, :unsubscribe_from)
|
298
|
+
send(:define_method, :unsubscribe_from) do |from|
|
243
299
|
unsubscribes.find_or_create_by(from: from)
|
244
|
-
|
300
|
+
end
|
245
301
|
|
246
|
-
send(:define_method, :subscriptions)
|
302
|
+
send(:define_method, :subscriptions) do
|
247
303
|
subscriptions = []
|
248
304
|
subscriptions << {
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
305
|
+
from: self,
|
306
|
+
from_type: self.class.name,
|
307
|
+
from_id: id,
|
308
|
+
from_name: :messages_directly_to_myself.l,
|
309
|
+
unsubscribe: unsubscribes.find_by(from: self)
|
254
310
|
}
|
255
311
|
collective_boxes.values.each do |boxes|
|
256
312
|
boxes.each do |box|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
313
|
+
next unless box.parent.allows_receiving_by?(self)
|
314
|
+
collective_name = box.parent.send(
|
315
|
+
MessageTrain.configuration.name_columns[
|
316
|
+
box.parent.class.table_name.to_sym
|
317
|
+
]
|
318
|
+
)
|
319
|
+
subscriptions << {
|
320
|
+
from: box.parent,
|
321
|
+
from_type: box.parent.class.name,
|
322
|
+
from_id: box.parent.id,
|
323
|
+
from_name: :messages_to_collective.l(
|
324
|
+
collective: collective_name
|
325
|
+
),
|
326
|
+
unsubscribe: unsubscribes.find_by(from: box.parent)
|
327
|
+
}
|
267
328
|
end
|
268
329
|
end
|
269
330
|
subscriptions
|
270
|
-
|
331
|
+
end
|
271
332
|
end
|
272
333
|
end
|
273
334
|
end
|
274
|
-
end
|
335
|
+
end
|
data/lib/message_train.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# MessageTrain module
|
1
2
|
module MessageTrain
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'active_record/railtie'
|
4
|
+
require 'action_controller/railtie'
|
5
|
+
require 'action_mailer/railtie'
|
6
|
+
require 'action_view/railtie'
|
7
|
+
require 'sprockets/railtie'
|
7
8
|
|
8
9
|
require 'rails-i18n'
|
9
10
|
|
@@ -17,4 +18,4 @@ module MessageTrain
|
|
17
18
|
require 'bootstrap_leather'
|
18
19
|
end
|
19
20
|
|
20
|
-
ActiveRecord::Base.send(:include, MessageTrain::Mixin)
|
21
|
+
ActiveRecord::Base.send(:include, MessageTrain::Mixin)
|
data/message_train.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: message_train 0.5.
|
5
|
+
# stub: message_train 0.5.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "message_train"
|
9
|
-
s.version = "0.5.
|
9
|
+
s.version = "0.5.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Karen Lundgren"]
|
14
|
-
s.date = "2016-03-
|
14
|
+
s.date = "2016-03-02"
|
15
15
|
s.description = "Rails 4 Engine providing private/public messaging for any object, such as Users or Groups"
|
16
16
|
s.email = "karen.e.lundgren@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -21,8 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
+
".rubocop.yml",
|
24
25
|
".ruby-gemset",
|
25
26
|
".ruby-version",
|
27
|
+
".scss-lint.yml",
|
26
28
|
".simplecov",
|
27
29
|
".travis.yml",
|
28
30
|
"Gemfile",
|
@@ -202,7 +204,6 @@ Gem::Specification.new do |s|
|
|
202
204
|
"spec/dummy/config/routes.rb",
|
203
205
|
"spec/dummy/config/secrets.yml",
|
204
206
|
"spec/dummy/config/settings.yml",
|
205
|
-
"spec/dummy/config/unused/temporary_i18n_debugging.rb",
|
206
207
|
"spec/dummy/db/migrate/20150721140013_devise_create_users.rb",
|
207
208
|
"spec/dummy/db/migrate/20150721141009_rolify_create_roles.rb",
|
208
209
|
"spec/dummy/db/migrate/20150721141128_create_groups.rb",
|
@@ -258,18 +259,18 @@ Gem::Specification.new do |s|
|
|
258
259
|
"spec/models/user_spec.rb",
|
259
260
|
"spec/rails_helper.rb",
|
260
261
|
"spec/spec_helper.rb",
|
261
|
-
"spec/support/attachments.rb",
|
262
262
|
"spec/support/controller_behaviors.rb",
|
263
263
|
"spec/support/controller_macros.rb",
|
264
|
-
"spec/support/conversations.rb",
|
265
264
|
"spec/support/factory_girl.rb",
|
266
265
|
"spec/support/feature_behaviors.rb",
|
267
|
-
"spec/support/
|
268
|
-
"spec/support/loaded_site.rb",
|
269
|
-
"spec/support/
|
270
|
-
"spec/support/
|
266
|
+
"spec/support/loaded_site/attachments.rb",
|
267
|
+
"spec/support/loaded_site/conversations.rb",
|
268
|
+
"spec/support/loaded_site/groups.rb",
|
269
|
+
"spec/support/loaded_site/loaded_site.rb",
|
270
|
+
"spec/support/loaded_site/messages.rb",
|
271
|
+
"spec/support/loaded_site/roles.rb",
|
272
|
+
"spec/support/loaded_site/users.rb",
|
271
273
|
"spec/support/shared_connection.rb",
|
272
|
-
"spec/support/users.rb",
|
273
274
|
"spec/support/utilities.rb"
|
274
275
|
]
|
275
276
|
s.homepage = "http://www.gemvein.com/museum/cases/message_train"
|
@@ -302,6 +303,10 @@ Gem::Specification.new do |s|
|
|
302
303
|
s.add_development_dependency(%q<sdoc>, ["~> 0.4.1"])
|
303
304
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
304
305
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
306
|
+
s.add_development_dependency(%q<pre-commit>, ["~> 0.27"])
|
307
|
+
s.add_development_dependency(%q<rubocop>, ["~> 0.37"])
|
308
|
+
s.add_development_dependency(%q<coffeelint>, ["~> 1.14"])
|
309
|
+
s.add_development_dependency(%q<scss_lint>, ["~> 0.47.0"])
|
305
310
|
s.add_development_dependency(%q<sqlite3>, ["~> 1.3"])
|
306
311
|
s.add_development_dependency(%q<devise>, ["~> 3.5"])
|
307
312
|
s.add_development_dependency(%q<rolify>, ["~> 4"])
|
@@ -335,6 +340,10 @@ Gem::Specification.new do |s|
|
|
335
340
|
s.add_dependency(%q<sdoc>, ["~> 0.4.1"])
|
336
341
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
337
342
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
343
|
+
s.add_dependency(%q<pre-commit>, ["~> 0.27"])
|
344
|
+
s.add_dependency(%q<rubocop>, ["~> 0.37"])
|
345
|
+
s.add_dependency(%q<coffeelint>, ["~> 1.14"])
|
346
|
+
s.add_dependency(%q<scss_lint>, ["~> 0.47.0"])
|
338
347
|
s.add_dependency(%q<sqlite3>, ["~> 1.3"])
|
339
348
|
s.add_dependency(%q<devise>, ["~> 3.5"])
|
340
349
|
s.add_dependency(%q<rolify>, ["~> 4"])
|
@@ -369,6 +378,10 @@ Gem::Specification.new do |s|
|
|
369
378
|
s.add_dependency(%q<sdoc>, ["~> 0.4.1"])
|
370
379
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
371
380
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
381
|
+
s.add_dependency(%q<pre-commit>, ["~> 0.27"])
|
382
|
+
s.add_dependency(%q<rubocop>, ["~> 0.37"])
|
383
|
+
s.add_dependency(%q<coffeelint>, ["~> 1.14"])
|
384
|
+
s.add_dependency(%q<scss_lint>, ["~> 0.47.0"])
|
372
385
|
s.add_dependency(%q<sqlite3>, ["~> 1.3"])
|
373
386
|
s.add_dependency(%q<devise>, ["~> 3.5"])
|
374
387
|
s.add_dependency(%q<rolify>, ["~> 4"])
|