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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/.ruby-gemset +1 -1
  4. data/.scss-lint.yml +7 -0
  5. data/.simplecov +1 -1
  6. data/.travis.yml +1 -1
  7. data/Gemfile +6 -2
  8. data/LICENSE.txt +2 -2
  9. data/README.rdoc +5 -5
  10. data/Rakefile +22 -21
  11. data/VERSION +1 -1
  12. data/app/assets/javascripts/message_train.js +1 -1
  13. data/app/assets/stylesheets/message_train.scss +29 -19
  14. data/app/controllers/concerns/message_train_support.rb +41 -37
  15. data/app/controllers/message_train/application_controller.rb +1 -0
  16. data/app/controllers/message_train/boxes_controller.rb +5 -4
  17. data/app/controllers/message_train/conversations_controller.rb +8 -7
  18. data/app/controllers/message_train/messages_controller.rb +25 -22
  19. data/app/controllers/message_train/participants_controller.rb +27 -23
  20. data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
  21. data/app/helpers/message_train/application_helper.rb +6 -8
  22. data/app/helpers/message_train/attachments_helper.rb +12 -4
  23. data/app/helpers/message_train/boxes_helper.rb +38 -11
  24. data/app/helpers/message_train/collectives_helper.rb +38 -12
  25. data/app/helpers/message_train/conversations_helper.rb +43 -35
  26. data/app/helpers/message_train/messages_helper.rb +32 -25
  27. data/app/mailers/message_train/application_mailer.rb +7 -4
  28. data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
  29. data/app/mailers/message_train/receipt_mailer.rb +14 -4
  30. data/app/models/message_train/attachment.rb +41 -25
  31. data/app/models/message_train/box.rb +159 -122
  32. data/app/models/message_train/conversation.rb +84 -41
  33. data/app/models/message_train/ignore.rb +8 -2
  34. data/app/models/message_train/message.rb +72 -42
  35. data/app/models/message_train/receipt.rb +30 -17
  36. data/app/models/message_train/unsubscribe.rb +1 -0
  37. data/app/views/application/404.html.haml +1 -1
  38. data/app/views/layouts/mailer.html.haml +2 -2
  39. data/app/views/layouts/mailer.text.haml +1 -1
  40. data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
  41. data/app/views/message_train/application/_widget.html.haml +1 -1
  42. data/app/views/message_train/application/results.json.jbuilder +1 -1
  43. data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
  44. data/app/views/message_train/boxes/_list_item.html.haml +1 -1
  45. data/app/views/message_train/boxes/show.html.haml +1 -1
  46. data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
  47. data/app/views/message_train/collectives/_list_item.html.haml +1 -1
  48. data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
  49. data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
  50. data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
  51. data/app/views/message_train/conversations/_toggle.html.haml +1 -1
  52. data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
  53. data/app/views/message_train/conversations/show.html.haml +2 -2
  54. data/app/views/message_train/conversations/show.json.jbuilder +5 -1
  55. data/app/views/message_train/messages/_form.html.haml +1 -1
  56. data/app/views/message_train/messages/_message.html.haml +6 -6
  57. data/app/views/message_train/messages/_toggle.html.haml +1 -1
  58. data/app/views/message_train/messages/show.json.jbuilder +5 -1
  59. data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
  60. data/app/views/message_train/participants/index.json.jbuilder +1 -1
  61. data/app/views/message_train/participants/show.json.jbuilder +1 -1
  62. data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
  63. data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
  64. data/app/views/message_train/unsubscribes/index.html.haml +1 -1
  65. data/config/environment.rb +1 -1
  66. data/config/initializers/date_time.rb +2 -2
  67. data/config/locales/en.yml +1 -1
  68. data/config/routes.rb +37 -15
  69. data/lib/generators/message_train/install/install_generator.rb +26 -11
  70. data/lib/generators/message_train/install/templates/initializer.rb +0 -2
  71. data/lib/generators/message_train/utils.rb +11 -4
  72. data/lib/message_train/configuration.rb +4 -5
  73. data/lib/message_train/engine.rb +1 -7
  74. data/lib/message_train/localization.rb +14 -18
  75. data/lib/message_train/mixin.rb +211 -150
  76. data/lib/message_train/version.rb +1 -0
  77. data/lib/message_train.rb +7 -6
  78. data/message_train.gemspec +24 -11
  79. data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
  80. data/spec/controllers/message_train/concerns_spec.rb +17 -13
  81. data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
  82. data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
  83. data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
  84. data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
  85. data/spec/dummy/Rakefile +2 -1
  86. data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
  87. data/spec/dummy/app/controllers/application_controller.rb +7 -7
  88. data/spec/dummy/app/models/group.rb +1 -1
  89. data/spec/dummy/app/models/role.rb +11 -7
  90. data/spec/dummy/app/models/user.rb +6 -5
  91. data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
  92. data/spec/dummy/app/views/layouts/application.html.haml +1 -1
  93. data/spec/dummy/app/views/pages/index.html.haml +1 -1
  94. data/spec/dummy/config/application.rb +23 -17
  95. data/spec/dummy/config/environments/development.rb +5 -4
  96. data/spec/dummy/config/environments/production.rb +10 -6
  97. data/spec/dummy/config/environments/test.rb +4 -3
  98. data/spec/dummy/config/initializers/assets.rb +2 -1
  99. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
  100. data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
  101. data/spec/dummy/config/initializers/devise.rb +63 -44
  102. data/spec/dummy/config/initializers/high_voltage.rb +1 -1
  103. data/spec/dummy/config/initializers/message_train.rb +5 -2
  104. data/spec/dummy/config/initializers/mime_types.rb +1 -1
  105. data/spec/dummy/config/initializers/paperclip.rb +5 -2
  106. data/spec/dummy/config/initializers/rolify.rb +3 -2
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
  108. data/spec/dummy/config/routes.rb +1 -3
  109. data/spec/dummy/config/settings.yml +1 -1
  110. data/spec/dummy/db/schema.rb +98 -98
  111. data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
  112. data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
  113. data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
  114. data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
  115. data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
  116. data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
  117. data/spec/dummy/db/seeds/users.seeds.rb +47 -42
  118. data/spec/dummy/db/test.sqlite3 +0 -0
  119. data/spec/factories/attachment.rb +6 -2
  120. data/spec/factories/group.rb +1 -4
  121. data/spec/factories/message.rb +29 -23
  122. data/spec/factories/user.rb +6 -4
  123. data/spec/features/boxes_spec.rb +76 -24
  124. data/spec/features/conversations_spec.rb +19 -7
  125. data/spec/features/messages_spec.rb +24 -5
  126. data/spec/features/unsubscribes_spec.rb +36 -9
  127. data/spec/helpers/message_train/application_helper_spec.rb +1 -1
  128. data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
  129. data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
  130. data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
  131. data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
  132. data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
  133. data/spec/message_train_spec.rb +3 -2
  134. data/spec/models/group_spec.rb +12 -9
  135. data/spec/models/message_train/attachment_spec.rb +33 -30
  136. data/spec/models/message_train/box_spec.rb +243 -60
  137. data/spec/models/message_train/conversation_spec.rb +16 -12
  138. data/spec/models/message_train/ignore_spec.rb +3 -1
  139. data/spec/models/message_train/message_spec.rb +22 -7
  140. data/spec/models/message_train/receipt_spec.rb +14 -4
  141. data/spec/models/role_spec.rb +10 -6
  142. data/spec/models/user_spec.rb +74 -22
  143. data/spec/rails_helper.rb +9 -4
  144. data/spec/spec_helper.rb +6 -54
  145. data/spec/support/controller_behaviors.rb +8 -5
  146. data/spec/support/controller_macros.rb +2 -2
  147. data/spec/support/factory_girl.rb +1 -1
  148. data/spec/support/feature_behaviors.rb +42 -13
  149. data/spec/support/loaded_site/attachments.rb +8 -0
  150. data/spec/support/loaded_site/conversations.rb +73 -0
  151. data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
  152. data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
  153. data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
  154. data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
  155. data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
  156. data/spec/support/shared_connection.rb +8 -6
  157. data/spec/support/utilities.rb +10 -10
  158. metadata +67 -10
  159. data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
  160. data/spec/support/attachments.rb +0 -4
  161. data/spec/support/conversations.rb +0 -23
@@ -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 = options[:only] ? [options[:only]].flatten : [:sender, :recipient]
9
- if options[:except]
10
- relationships = relationships - [options[:except]].flatten
11
- end
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 :receipts, as: :recipient, class_name: 'MessageTrain::Receipt'
19
- has_many :unsubscribes, as: :recipient, class_name: 'MessageTrain::Unsubscribe'
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[:address_book_method]
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[:collectives_for_recipient]
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[:valid_recipients]
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[table_sym].present?
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
- valid_senders_method = MessageTrain.configuration.valid_senders_methods[self.class.table_name.to_sym] || :self_collection
65
- send(valid_senders_method)
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?) { |sender|
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
- valid_recipients_method = MessageTrain.configuration.valid_recipients_methods[self.class.table_name.to_sym] || :self_collection
74
- send(valid_recipients_method)
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?) { |recipient|
78
- if valid_recipients.nil? or valid_recipients.empty?
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) { # This turns a single record into an active record 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: self.id)
88
- }
113
+ model.where(id: id)
114
+ end
89
115
 
90
116
  if relationships.include? :recipient
91
- send(:define_method, :box) { |*args|
117
+ send(:define_method, :box) do |*args|
92
118
  case args.count
93
- when 0
94
- division = :in
95
- participant = self
96
- when 1
97
- division = args[0] || :in
98
- participant = self
99
- when 2
100
- division = args[0] || :in
101
- participant = args[1] || self
102
- else
103
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..2', wrong: args.count.to_s, thing: self.class.name)
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) { |*args|
138
+ send(:define_method, :collective_boxes) do |*args|
109
139
  case args.count
110
- when 0
111
- division = :in
112
- participant = self
113
- when 1
114
- division = args[0] || :in
115
- participant = self
116
- when 2
117
- division = args[0] || :in
118
- participant = args[1] || self
119
- else # Treat all but the division as a hash of options
120
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..2', wrong: args.count.to_s, thing: self.class.name)
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
- collective_box_tables = MessageTrain.configuration.collectives_for_recipient_methods
156
+ cb_tables = MessageTrain.configuration
157
+ .collectives_for_recipient_methods
123
158
  collective_boxes = {}
124
- unless collective_box_tables.empty?
125
- collective_box_tables.each do |table_sym, collectives_method|
126
- class_name = MessageTrain.configuration.recipient_tables[table_sym]
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
- unless collectives.empty?
130
- collectives.each do |collective|
131
- collective_boxes[table_sym] ||= []
132
- collective_boxes[table_sym] << collective.box(division, participant)
133
- end
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) { |*args|
178
+ send(:define_method, :all_boxes) do |*args|
141
179
  case args.count
142
- when 0
143
- participant = self
144
- when 1
145
- participant = args[0] || self
146
- else # Treat all but the division as a hash of options
147
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..1', wrong: args.count.to_s, thing: self.class.name)
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 { |division| MessageTrain::Box.new(self, division, participant) }
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) { |*args|
198
+ send(:define_method, :conversations) do |*args|
155
199
  case args.count
156
- when 0
157
- division = :in
158
- participant = self
159
- when 1
160
- division = args[0] || :in
161
- participant = self
162
- when 2
163
- division = args[0] || :in
164
- participant = args[1] || self
165
- else # Treat all but the division as a hash of options
166
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..2', wrong: args.count.to_s, thing: self.class.name)
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(self)
216
+ my_conversations = MessageTrain::Conversation.with_messages_through(
217
+ self
218
+ )
169
219
  case division
170
- when :in
171
- my_conversations.with_untrashed_to(participant)
172
- when :sent
173
- my_conversations.with_untrashed_by(participant)
174
- when :all
175
- my_conversations.with_untrashed_for(participant)
176
- when :drafts
177
- my_conversations.with_drafts_by(participant)
178
- when :trash
179
- my_conversations.with_trashed_for(participant)
180
- when :ignored
181
- my_conversations.ignored(participant)
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) { |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 self.respond_to?(:messages) || allows_sending_by?(participant)
238
+ if respond_to?(:messages) || allows_sending_by?(participant)
191
239
  divisions += [:sent, :drafts]
192
240
  end
193
- if allows_receiving_by?(participant)
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 { |division| MessageTrain::Box.new(self, division, participant) }
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) { |*args|
248
+ send(:define_method, :all_conversations) do |*args|
201
249
  case args.count
202
- when 0
203
- participant = self
204
- when 1
205
- participant = args[0] || self
206
- else # Treat all but the division as a hash of options
207
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..1', wrong: args.count.to_s, thing: self.class.name)
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) { |*args|
269
+ send(:define_method, :all_messages) do |*args|
218
270
  case args.count
219
- when 0
220
- participant = self
221
- when 1
222
- participant = args[0] || self
223
- else # Treat all but the division as a hash of options
224
- raise :wrong_number_of_arguments_for_thing_expected_right_got_wrong.l(right: '0..1', wrong: args.count.to_s, thing: self.class.name)
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?) { |from|
239
- unsubscribed_from_all? or unsubscribes.where(from: from).exists?
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) { |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
- from: self,
250
- from_type: self.class.name,
251
- from_id: self.id,
252
- from_name: :messages_directly_to_myself.l,
253
- unsubscribe: self.unsubscribes.find_by(from: self)
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
- if box.parent.allows_receiving_by?(self)
258
- collective_name = box.parent.send(MessageTrain.configuration.name_columns[box.parent.class.table_name.to_sym])
259
- subscriptions << {
260
- from: box.parent,
261
- from_type: box.parent.class.name,
262
- from_id: box.parent.id,
263
- from_name: :messages_to_collective.l(collective: collective_name),
264
- unsubscribe: self.unsubscribes.find_by(from: box.parent)
265
- }
266
- end
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
@@ -1,3 +1,4 @@
1
+ # Message Train module
1
2
  module MessageTrain
2
3
  VERSION = File.read(File.expand_path('../../../VERSION', __FILE__))
3
4
 
data/lib/message_train.rb CHANGED
@@ -1,9 +1,10 @@
1
+ # MessageTrain module
1
2
  module MessageTrain
2
- require "active_record/railtie"
3
- require "action_controller/railtie"
4
- require "action_mailer/railtie"
5
- require "action_view/railtie"
6
- require "sprockets/railtie"
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)
@@ -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.2 ruby lib
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.2"
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-01"
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/groups.rb",
268
- "spec/support/loaded_site.rb",
269
- "spec/support/messages.rb",
270
- "spec/support/roles.rb",
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"])