voltron-notify 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 698c826b9ee01c01f1daea0727c9f9a858bd53f9
4
- data.tar.gz: f2f0cb75ae14e44a046c6fc5faf590a1efbdb02c
3
+ metadata.gz: aa1739df09fe0932193f362f2cbfc87a0d1cf75a
4
+ data.tar.gz: ebd82b3a4221a9a1ba32fd249d635a749740bcfe
5
5
  SHA512:
6
- metadata.gz: d44cbe91644c6cfcc2bb082ed1f1244969a87ed69eb1abfb1033ed968cfde3f5810c1319ad4d9295fce5a17c5b5a3fc953e7ade7c6f8bc5d51922606e7769ada
7
- data.tar.gz: 87ab64f59e3fb1b486eb869df10263625f112198792b5d4b84981873e42442a65c854d1e3e142f1450bef3c606b9f820bc67cf6c2529f34a8b9fd9a6b0491959
6
+ metadata.gz: 0e6772721e3818480d21d44a8b9e5238a913da8cbbefd370edff5be0a809fde7219bbd4d526a49c835eeaef69a3a4e6d8da4fabe3323687dfe21122387be2a20
7
+ data.tar.gz: e71e0911228ece8b8e94ee430bb55200005d6ed560e2cca4b90cf4ba8a89ccc937c686442cc6d6662b5f75eb99784eafd57756855d466fc0fd1f75ea88765e7e
data/Gemfile CHANGED
@@ -2,4 +2,8 @@ source 'https://rubygems.org'
2
2
  source 'https://gem.minow.io'
3
3
 
4
4
  # Specify your gem's dependencies in voltron-notify.gemspec
5
- gemspec
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'coveralls', require: false
9
+ end
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- [![Code Climate](https://codeclimate.com/github/ehainer/voltron-notify.png)](https://codeclimate.com/github/ehainer/voltron-notify)
1
+ [![Coverage Status](https://coveralls.io/repos/github/ehainer/voltron-notify/badge.svg?branch=master)](https://coveralls.io/github/ehainer/voltron-notify?branch=master)
2
2
  [![Build Status](https://travis-ci.org/ehainer/voltron-notify.svg?branch=master)](https://travis-ci.org/ehainer/voltron-notify)
3
+ [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
3
4
 
4
5
  # Voltron::Notify
5
6
 
6
- Voltron Notify is an attempt to join Twilio's SMS api with Rails' default mailer functionality into one single method.
7
+ Trying to make the task of sending both email and SMS notifications as easy as possible, while also providing a simple(ish) way of tracking each notification sent.
8
+
7
9
 
8
10
 
9
11
  ## Installation
@@ -11,12 +13,12 @@ Voltron Notify is an attempt to join Twilio's SMS api with Rails' default mailer
11
13
  Add this line to your application's Gemfile:
12
14
 
13
15
  ```ruby
14
- gem 'voltron-notify'
16
+ gem 'voltron-notify', '~> 0.2.1'
15
17
  ```
16
18
 
17
19
  And then execute:
18
20
 
19
- $ bundle
21
+ $ bundle install
20
22
 
21
23
  Or install it yourself as:
22
24
 
@@ -40,7 +42,7 @@ end
40
42
 
41
43
  `notifyable` will create a `notifications` association on whatever model it is called on. The one optional argument should be a hash with default SMS/Email ActiveJob options. See "ActiveJob Integration" below for more info on how/when the default options will be used.
42
44
 
43
- Defined default options should look like so:
45
+ Defined default options should (or rather, could) look like so:
44
46
 
45
47
  ```ruby
46
48
  class User < ActiveRecord::Base
@@ -58,24 +60,24 @@ Once done, you can utilize Voltron Notify like so:
58
60
 
59
61
  @user.notifications.create do |n|
60
62
  # First argument is SMS message text, second argument is hash containing zero or more of: [:to, :from]
61
- n.sms "This is my message", to: "1 (234) 567-8910"
63
+ n.sms 'This is my message', to: '1 (234) 567-8910'
62
64
 
63
65
  # and/or ...
64
66
 
65
67
  # First argument is email subject, remaining arguments can consist of [:to, :from] or any other param you'd like,
66
68
  # they will all be converted to @variables for use in the mailer template
67
- n.email "This is the mail subject", { to: "info@example.com", param_one: "Hi there", param_two: "" }
69
+ n.email 'This is the mail subject', { to: 'info@example.com', param_one: 'Hi there', param_two: '' }
68
70
  end
69
71
  ```
70
72
 
71
73
  While you may specify the :to and :from as one of the arguments, by default the :from value of each notification type comes from `Voltron.config.notify.email_from` and `Voltron.config.notify.sms_from`. The value of :to by default will attempt to be retrieved by calling `.phone` or `.email` on the notifyable model itself. So given a User model with attributes (or methods) `email` and `phone`, the following will send notifications to those values:
72
74
 
73
75
  ```ruby
74
- @user = User.find(1) #<User id: 1, phone: "1234567890", email: "info@example.com", created_at: "2016-09-23 16:49:20", updated_at: "2016-09-23 16:49:20">
76
+ @user = User.find(1) #<User id: 1, phone: '1234567890', email: 'info@example.com', created_at: '2016-09-23 16:49:20', updated_at: '2016-09-23 16:49:20'>
75
77
 
76
78
  @user.notifications.create do |n|
77
- n.sms "Hello from SMS" # Will send to +1 (123) 456-7890
78
- n.email "Hello from Email" # Will send to info@example.com
79
+ n.sms 'Hello from SMS' # Will send to +1 (123) 456-7890
80
+ n.email 'Hello from Email' # Will send to info@example.com
79
81
  end
80
82
 
81
83
  # @user.notifications.build { |n| ... } ... followed by @user.save works the same way
@@ -85,18 +87,19 @@ Optionally, you may pass a block to the `sms` or `email` methods that allows for
85
87
 
86
88
  ```ruby
87
89
  @user.notifications.create do |n|
88
- n.sms "Hello from SMS" do
89
- attach "picture.jpg" # Attach an image using the rails asset pipeline by specifying just the filename
90
- attach "http://www.someimagesite.com/example/demo/image.png" # Or just provide a url to a supported file beginning with "http"
90
+ n.sms 'Hello from SMS' do
91
+ attach 'picture.jpg' # Attach an image using the rails asset pipeline by specifying just the filename
92
+ attach 'http://www.someimagesite.com/example/demo/image.png' # Or just provide a url to a supported file beginning with 'http'
91
93
  end
92
94
 
93
- n.email "Hello from Email" do
94
- attach "picture.jpg" # Uses the asset pipeline like above
95
- attach "http://www.example.com/picture.jpg" # This WILL NOT work, email attachments don't work that way
95
+ n.email 'Hello from Email' do
96
+ attach 'picture.jpg' # Uses the asset pipeline like above
97
+ attach 'http://www.example.com/picture.jpg' # This WILL NOT work, email attachments don't work that way
96
98
 
97
99
  mailer SiteMailer # Default: Voltron::NotificationMailer
98
100
  method :send_my_special_notification # Default: :notify
99
101
  arguments @any, list, of.arguments, :you, would, @like # In this case, the arguments used by SiteMailer.send_my_special_notification()
102
+ template 'my_mailer/sub_dir/custom_template' # Default: 'voltron/notification_mailer/notify.html.erb'
100
103
  end
101
104
  end
102
105
  ```
@@ -108,13 +111,15 @@ In the case of the methods `mailer`, `method`, `arguments`, and `template`, belo
108
111
  | mailer | Voltron::NotificationMailer | Defines what mailer class should be used to handle the sending of email notifications. Can be defined as the actual class name or a string, even in the format '&lt;module&gt;/&lt;mailer&gt;'. It is eventually converted to a string anyways, converted to a valid format with [classify](https://apidock.com/rails/v4.2.7/String/classify) and then instantiated with [constantize](https://apidock.com/rails/String/constantize) |
109
112
  | method | :notify | Specifies what method within the defined mailer should be called. Can be a string or symbol |
110
113
  | arguments | nil | Accepts an unlimited number of arguments that will be passed directly through to your mailer method Can be anything you want, so long as +mailer+.+method+() will understand it. |
111
- | template | nil, but due to ActionMailer's default behavior, assuming +mailer+ and +method+ are not modified, it will look for `app/views/voltron/notification_mailer/notify.<format>.erb` | Overrides the default mailer template by parsing a single string argument into separate [template_path](http://guides.rubyonrails.org/action_mailer_basics.html#mailer-views) and [template_name](http://guides.rubyonrails.org/action_mailer_basics.html#mailer-views) arguments for the +mail+ method. Note that this argument should be the path relative to your applications `app/views` directory, and that it strips any file extensions. So, in the case of a view located at `app/views/my_mailer/sub_dir/special_template.html.erb` you can specify the path `my_mailer/sub_dir/special_template`. Depending on what format email you've chosen to send it will look for `special_template.<format>.erb` |
114
+ | template | nil, but due to ActionMailer's default behavior, assuming `mailer` and `method` are not modified, it will look for `app/views/voltron/notification_mailer/notify.<format>.erb` | Overrides the default mailer template by parsing a single string argument into separate [template_path](http://guides.rubyonrails.org/action_mailer_basics.html#mailer-views) and [template_name](http://guides.rubyonrails.org/action_mailer_basics.html#mailer-views) arguments for the `mail` method. Note that this argument should be the path relative to your applications `app/views` directory, and that it strips any file extensions. So, in the case of a view located at `app/views/my_mailer/sub_dir/special_template.html.erb` you can specify the path `my_mailer/sub_dir/special_template`. Depending on what format email you've chosen to send it will look for `special_template.<format>.erb` |
115
+
112
116
  Note that both SMS and Email notifications have validations on the :to/:from fields, the email subject, and the SMS body text. Since `notifications` is an association, any errors in the actual notification content will bubble up, possibly preventing the `notifyable` model from saving. For that reason, it may be more logical to instead use a @notifyable.notifications.build / @notifyable.save syntax to properly handle errors that may occur.
113
117
 
114
118
 
119
+
115
120
  ## ActiveJob Integration
116
121
 
117
- Voltron Notify supports sending both email (via deliver_later) and SMS (via Voltron::SmsJob and perform_later). To have all notifications be handled by ActiveJob in conjunction with Sidekiq/Resque/whatever you need only set the config value `Voltron.config.notify.use_queue` to `true`. If ActiveJob is configured properly notifications will send that way instead. You may also optionally set the delay for each notification by setting the value of `Voltron.config.notify.delay` to any time value (i.e. 5.minutes, 3.months, 0.seconds)
122
+ Voltron Notify supports sending both email (via deliver_later) and SMS (via Voltron::SmsJob and perform_later). To have all notifications be handled by ActiveJob in conjunction with Sidekiq/Resque/whatever you need only set the config value `Voltron.config.notify.use_queue` to `true`. If ActiveJob is configured properly notifications will send that way instead.
118
123
 
119
124
  If the value of `Voltron.config.notify.use_queue` is `true`, additional methods for sending SMS/Email can be used to further control the ActiveJob params.
120
125
 
@@ -127,7 +132,6 @@ For the `email` method:
127
132
  | deliver_later | Yes, same as what [deliver_later](https://apidock.com/rails/v4.2.7/ActionMailer/MessageDelivery/deliver_later) would accept. These arguments will come from the defaults specified when `notifyable` is called in the model. Default arguments are always overridden by the same options defined in this methods arguments. See documentation of `notifyable` and it's accepted arguments above. | Same as [deliver_later](https://apidock.com/rails/v4.2.7/ActionMailer/MessageDelivery/deliver_later), except this will not occur until the parent notification association is saved | Yes, if `Voltron.config.notify.use_queue` is truthy. No otherwise |
128
133
  | deliver_later! | Yes, same as what [deliver_later!](https://apidock.com/rails/v4.2.7/ActionMailer/MessageDelivery/deliver_later%21) would accept. These arguments will come from the defaults specified when `notifyable` is called in the model. Default arguments are always overridden by the same options defined in this methods arguments. See documentation of `notifyable` and it's accepted arguments above. | Same as [deliver_later!](https://apidock.com/rails/v4.2.7/ActionMailer/MessageDelivery/deliver_later%21), except this will not occur until the parent notification association is saved | No |
129
134
 
130
-
131
135
  For the `sms` method:
132
136
 
133
137
  | Queue Specific Methods Available | Accepts Arguments? | Behavior | Default Behavior If Not Manually Called |
@@ -142,9 +146,9 @@ Example usage:
142
146
  @user = User.find(1)
143
147
 
144
148
  @user.notifications.build do |n|
145
- n.sms("Immediate Message").deliver_now # Will deliver the SMS as soon as the notification is saved
146
- n.sms("Delayed Message").deliver_later(queue: 'sms', wait_until: 10.minutes.from_now) # Will deliver the SMS via +perform_now+ with ActiveJob
147
- n.email("Delayed Mail Subject", { param_one: "Hi there", param_two: "" }).deliver_later(wait: 5.minutes)
149
+ n.sms('Immediate Message').deliver_now # Will deliver the SMS as soon as the notification is saved
150
+ n.sms('Delayed Message').deliver_later(queue: 'sms', wait_until: 10.minutes.from_now) # Will deliver the SMS via +perform_now+ with ActiveJob
151
+ n.email('Delayed Mail Subject', { param_one: 'Hi there', param_two: '' }).deliver_later(wait: 5.minutes) # Will pass through to ActionMailer's +deliver_later+ method
148
152
  end
149
153
 
150
154
  @user.save # Will finally perform the actual actions defined. Basically, +deliver_*+ does nothing until the notification is saved.
@@ -158,35 +162,40 @@ Also supported are Twilio status update callbacks for SMS notifications. To enab
158
162
  ```ruby
159
163
  Rails.application.routes.draw do
160
164
 
161
- allow_notification_update(options={})
165
+ allow_notification_update [options]
162
166
 
163
167
  end
164
168
  ```
165
169
 
166
- Without specifying, the default options for notification updates are as follows:
170
+ Without specifying, the default options hash for notification updates are as follows:
167
171
 
168
- | Option | Default | Comment |
169
- |------------|----------------------|---------------------------------------------------------------------------------------------------------------------------|
170
- | path | /notification/update | The default url path that Twilio will POST updates to. Can be anything you want so long as it's a valid URL path |
171
- | controller | voltron/notification | The controller that will handle the notification update (in this case `app/controllers/voltron/notification_controller.rb`) |
172
- | action | update | The controller action (method) that will perform the update |
172
+ | Option (hash key) | Default (hash value) | Comment |
173
+ |-----------------------|----------------------------------|---------------------------------------------------------------------------------------------------------------------------|
174
+ | path | /notification/update | The default url path that Twilio will POST updates to. Can be anything you want so long as it's a valid URL path |
175
+ | controller | voltron/notification | The controller that will handle the notification update (in this case `app/controllers/voltron/notification_controller.rb`) |
176
+ | action | update | The controller action (method) that will perform the update |
173
177
 
174
178
  If the value of `controller` or `action` are modified, it is assumed that whatever they point to will handle SMS notification updates. See the description column for "StatusCallback" parameter [here](https://www.twilio.com/docs/api/rest/sending-messages) for information on what Twilio will POST to the callback url. Or, take a look at this gems `app/controller/voltron/notification_controller.rb` file to see what it does by default.
175
179
 
176
- In order for `allow_notification_update` to generate the correct callback url, please ensure the value of `Voltron.config.base_url` is a valid host name. By default it will attempt to obtain this information from the `:host` parameter of `Rails.application.config.action_controller.default_url_options` but if specified in the Voltron initializer that will
180
+ In order for `allow_notification_update` to generate the correct callback url, please ensure the value of `Voltron.config.base_url` is a valid host name. By default it will attempt to obtain this information from the `:host` parameter of `Rails.application.config.action_controller.default_url_options` but if specified in the Voltron initializer that will be used instead.
181
+
182
+ Note that `allow_notification_update` does nothing if running on a host matching `localhost` or `127.0.0.1` Since Twilio can't reach locally running apps to POST to, the app will not even provide Twilio with the callback url to try it. If you have a local app host named Twilio will try and POST to it, but will obviously fail for the reasons previously stated. Basically, this feature only works on remotely accessible hosts.
177
183
 
178
- Note that `allow_notification_update` does nothing if running on a host matching `/localhost|127\.0\.0\.1/i` Since Twilio can't reach locally running apps to POST to, the app will not even provide Twilio with the callback url to try it. If you have a local app host named Twilio will try and POST to it, but will obviously fail for the reasons previously stated. Basically, this feature only works on remotely accessible hosts.
179
184
 
180
185
 
181
- ## Development
186
+ ## Translation
187
+
188
+ When the install generator is run (see Installation), notification specific translations will appear in the Voltron translation file, `app/config/locales/voltron.yml`. If this file exists already the notification specific translations will be merged in as needed, without overwriting anything that might already be defined. All translations should be self explanatory, just modify as you see fit.
189
+
182
190
 
183
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
184
191
 
185
192
  ## Contributing
186
193
 
187
194
  Bug reports and pull requests are welcome on GitHub at https://github.com/ehainer/voltron-notify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
188
195
 
196
+
197
+
189
198
  ## License
190
199
 
191
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
200
+ The gem is available as open source under the terms of the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.en.html).
192
201
 
@@ -1,6 +1,6 @@
1
1
  class Voltron::Notification::EmailNotification < ActiveRecord::Base
2
2
 
3
- belongs_to :notification
3
+ belongs_to :notification, inverse_of: :email_notifications
4
4
 
5
5
  after_initialize :setup
6
6
 
@@ -54,7 +54,7 @@ class Voltron::Notification::EmailNotification < ActiveRecord::Base
54
54
 
55
55
  def template(fullpath)
56
56
  parts = fullpath.split('/')
57
- self.template_name = parts.pop.sub(/\.(html|text)\..*$/, '')
57
+ self.template_name = parts.pop.sub(/\.[a-z_]+\.[^\.]+$/i, '')
58
58
  self.template_path = parts.join('/')
59
59
  end
60
60
 
@@ -99,7 +99,7 @@ class Voltron::Notification::EmailNotification < ActiveRecord::Base
99
99
  @mailer_arguments = nil
100
100
  self.mailer_class ||= Voltron.config.notify.default_mailer
101
101
  self.mailer_method ||= Voltron.config.notify.default_method
102
- template(Voltron.config.notify.default_template)
102
+ template(Voltron.config.notify.default_template) if self.template_name.blank? || self.template_path.blank?
103
103
  end
104
104
 
105
105
  def mail_options
@@ -6,7 +6,7 @@ class Voltron::Notification::SmsNotification < ActiveRecord::Base
6
6
 
7
7
  has_many :attachments
8
8
 
9
- belongs_to :notification
9
+ belongs_to :notification, inverse_of: :sms_notifications
10
10
 
11
11
  after_initialize :setup
12
12
 
@@ -62,7 +62,7 @@ class Voltron::Notification::SmsNotification < ActiveRecord::Base
62
62
  begin
63
63
  to_formatted
64
64
  true
65
- rescue => e
65
+ rescue ::Twilio::REST::RequestError => e
66
66
  Voltron.log e.message, 'Notify', Voltron::Notify::LOG_COLOR
67
67
  false
68
68
  end
@@ -156,8 +156,8 @@ class Voltron::Notification::SmsNotification < ActiveRecord::Base
156
156
 
157
157
  def format(input)
158
158
  # Try to format the number via Twilio's api
159
- # raises an exception if the input was invalid
160
- number = lookup.phone_numbers.get input
159
+ raise ::Twilio::REST::RequestError.new('Phone number cannot be blank') if input.blank?
160
+ number = lookup.phone_numbers.get input.to_s
161
161
  number.phone_number
162
162
  end
163
163
 
@@ -1,24 +1,22 @@
1
1
  module Voltron
2
2
  class Notification < ActiveRecord::Base
3
3
 
4
- belongs_to :notifyable, polymorphic: true
4
+ belongs_to :notifyable, polymorphic: true, inverse_of: :notifications
5
5
 
6
- has_many :sms_notifications
6
+ has_many :sms_notifications, inverse_of: :notification, validate: true, autosave: true
7
7
 
8
- has_many :email_notifications
8
+ has_many :email_notifications, inverse_of: :notification, validate: true, autosave: true
9
9
 
10
10
  before_validation :prepare
11
11
 
12
- before_validation :validate
13
-
14
12
  PERMITTED_ATTRIBUTES = [:to, :from]
15
13
 
16
- def email(subject, **args, &block)
14
+ def email(subject, options={}, &block)
17
15
  # Get the remaining args as params, that will eventually become assigns in the mailer template
18
- params = { subject: subject, notifyable.class.name.downcase => notifyable }.compact.merge(**args)
16
+ params = { subject: subject, notifyable.class.name.downcase => notifyable }.compact.merge(options)
19
17
 
20
18
  # Build the options hash from the provided arguments
21
- options = { subject: subject }.merge(**args.select { |k, _| PERMITTED_ATTRIBUTES.include?(k.to_sym) })
19
+ options = { subject: subject }.merge(options.select { |k, _| PERMITTED_ATTRIBUTES.include?(k.to_sym) })
22
20
 
23
21
  # Build a new SMS notification object
24
22
  notification_email = email_notifications.build(options)
@@ -33,9 +31,9 @@ module Voltron
33
31
  notification_email
34
32
  end
35
33
 
36
- def sms(message, **args, &block)
34
+ def sms(message, options={}, &block)
37
35
  # Build the options hash from the provided arguments
38
- options = { message: message, from: Voltron.config.notify.sms_from }.merge(**args)
36
+ options = { message: message, from: Voltron.config.notify.sms_from }.merge(options)
39
37
 
40
38
  # Build a new SMS notification object
41
39
  notification_sms = sms_notifications.build(options)
@@ -64,15 +62,6 @@ module Voltron
64
62
 
65
63
  private
66
64
 
67
- def validate
68
- # Add SMS/Email related errors to self
69
- (sms_notifications.to_a + email_notifications.to_a).each do |n|
70
- unless n.valid?
71
- n.errors.full_messages.each { |msg| self.errors.add(:base, msg) }
72
- end
73
- end
74
- end
75
-
76
65
  def prepare
77
66
  # Set the to value for both the email and phone, if any on this model
78
67
  # This method is also called from the before_validation block in the notify module
@@ -1,20 +1,19 @@
1
1
  # This file will be merged with various other Voltron related YAML files with priority
2
- # given to what exists in this file to begin with (nothing you add/modify here will be overwritten)
3
- # whenever you run `rails g voltron:<gem_name>:install`,
4
- # only if the gem in question has any locale data associated with it
2
+ # given to what exists in this file to begin with (meaning: nothing you add/modify here will be overwritten)
3
+ # whenever you run `rails g voltron:<gem_name>:install`
5
4
 
6
5
  ---
7
6
  en:
8
7
  activerecord:
9
8
  attributes:
10
- voltron/notification/email_notification:
11
- to: Recipient
12
- subject: Subject
13
- voltron/notification/sms_notification:
9
+ notifications/sms_notifications:
14
10
  to: Recipient
15
11
  from: Sender
16
12
  message: Message
17
13
  status: Status
14
+ notifications/email_notifications:
15
+ to: Recipient
16
+ subject: Subject
18
17
  voltron:
19
18
  notification:
20
19
  email:
@@ -25,4 +24,4 @@ en:
25
24
  from_blank: cannot be blank
26
25
  message_blank: cannot be blank
27
26
  invalid_phone: number "%{number}" is not a valid phone number
28
- status_invalid: must be one of accepted, queued, sending, sent, delivered, received, failed, undelivered, or unknown
27
+ status_invalid: must be one of accepted, queued, sending, sent, delivered, received, failed, undelivered, or unknown
@@ -95,9 +95,8 @@ CONTENT
95
95
 
96
96
  File.open(locale_path, 'w') do |f|
97
97
  f.puts '# This file will be merged with various other Voltron related YAML files with priority'
98
- f.puts '# given to what exists in this file to begin with (nothing you add/modify here will be overwritten)'
99
- f.puts '# whenever you run `rails g voltron:<gem_name>:install`,'
100
- f.puts '# only if the gem in question has any locale data associated with it'
98
+ f.puts '# given to what exists in this file to begin with (meaning: nothing you add/modify here will be overwritten)'
99
+ f.puts '# whenever you run `rails g voltron:<gem_name>:install`'
101
100
  f.puts
102
101
  f.puts notification_locale.stringify_keys.to_yaml(line_width: -1)
103
102
  end
@@ -1,5 +1,5 @@
1
1
  module Voltron
2
2
  module Notify
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
@@ -9,42 +9,9 @@ module Voltron
9
9
  LOG_COLOR = :light_yellow
10
10
 
11
11
  def notifyable(defaults={})
12
- include InstanceMethods
13
-
14
12
  @_notification_defaults = defaults.with_indifferent_access
15
13
 
16
- before_validation :validate_notifications
17
-
18
- after_validation :clean_notification_validation
19
-
20
- has_many :notifications, as: :notifyable, class_name: '::Voltron::Notification'
21
- end
22
-
23
- module InstanceMethods
24
-
25
- private
26
-
27
- def validate_notifications
28
- # Find all notification records that haven't been saved yet
29
- self.notifications.select(&:new_record?).each do |notification|
30
-
31
- # Set the to value for both the email and phone, if any on this model
32
- notification.to self.try(:email), self.try(:phone)
33
-
34
- # If not valid, populate the childs error messages in this models errors object
35
- unless notification.valid?
36
- notification.errors.messages.each do |k, errors|
37
- errors.each { |error| self.errors.add k, error }
38
- end
39
- end
40
- end
41
- end
42
-
43
- def clean_notification_validation
44
- # Cleanup, remove the notifications key from the error messages,
45
- # All of the actual errors are populated into "notifications.<type>" keys above
46
- self.errors.delete :notifications
47
- end
14
+ has_many :notifications, as: :notifyable, inverse_of: :notifyable, validate: true, autosave: true, class_name: '::Voltron::Notification'
48
15
  end
49
16
  end
50
17
  end
@@ -23,8 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'rack', '>= 1.6'
24
24
  spec.add_dependency 'voltron', '~> 0.2', '>= 0.2.1'
25
25
 
26
- spec.add_development_dependency 'simplecov', '~> 0.11'
27
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
28
26
  spec.add_development_dependency 'bundler', '~> 1.12'
29
27
  spec.add_development_dependency 'rake', '~> 11.3'
30
28
  spec.add_development_dependency 'rspec', '~> 3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voltron-notify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hainer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,34 +72,6 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 0.2.1
75
- - !ruby/object:Gem::Dependency
76
- name: simplecov
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '0.11'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '0.11'
89
- - !ruby/object:Gem::Dependency
90
- name: codeclimate-test-reporter
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '1.0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '1.0'
103
75
  - !ruby/object:Gem::Dependency
104
76
  name: bundler
105
77
  requirement: !ruby/object:Gem::Requirement
@@ -270,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
242
  version: '0'
271
243
  requirements: []
272
244
  rubyforge_project:
273
- rubygems_version: 2.6.6
245
+ rubygems_version: 2.6.11
274
246
  signing_key:
275
247
  specification_version: 4
276
248
  summary: Send notifications easier