Skip to content

Commit

Permalink
Add ApplicationNotifier and ApplicationDeliveryMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 24, 2024
1 parent 181f349 commit 54a724c
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/generators/noticed/delivery_method_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DeliveryMethodGenerator < Rails::Generators::NamedBase
desc "Generates a class for a custom delivery method with the given NAME."

def generate_notification
template "application_delivery_method.rb", "app/notifiers/delivery_methods/application_delivery_method.rb"
template "delivery_method.rb", "app/notifiers/delivery_methods/#{singular_name}.rb"
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/generators/noticed/notifier_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NotifierGenerator < Rails::Generators::NamedBase
desc "Generates a notification with the given NAME."

def generate_notification
template "application_notifier.rb", "app/notifiers/application_notifier.rb"
template "notifier.rb", "app/notifiers/#{file_path}_notifier.rb"
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationDeliveryMethod < Noticed::DeliveryMethod
end
2 changes: 2 additions & 0 deletions lib/generators/noticed/templates/application_notifier.rb.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationNotifier < Noticed::Event
end
2 changes: 1 addition & 1 deletion lib/generators/noticed/templates/delivery_method.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeliveryMethods::<%= class_name %> < Noticed::DeliveryMethod
class DeliveryMethods::<%= class_name %> < ApplicationDeliveryMethod
# Specify the config options your delivery method requires in its config block
required_options # :foo, :bar

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/noticed/templates/notifier.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# <%= class_name %>.with(record: @post, message: "New post").deliver(User.all)

class <%= class_name %>Notifier < Noticed::Event
class <%= class_name %>Notifier < ApplicationNotifier
# Add your delivery methods
#
# deliver_by :email do |config|
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/notifiers/application_notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationNotifier < Noticed::Event
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/bulk_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class BulkNotifier < Noticed::Event
class BulkNotifier < ApplicationNotifier
bulk_deliver_by :webhook, url: "https://example.org/bulk"
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/comment_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CommentNotifier < Noticed::Event
class CommentNotifier < ApplicationNotifier
deliver_by :test

# delivery_by :email, mailer: "UserMailer", method: "new_comment"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationDeliveryMethod < Noticed::DeliveryMethod
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/priority_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class PriorityNotifier < Noticed::Event
class PriorityNotifier < ApplicationNotifier
deliver_by :test, priority: 2
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/queue_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class QueueNotifier < Noticed::Event
class QueueNotifier < ApplicationNotifier
deliver_by :test, queue: :example_queue
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/receipt_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ReceiptNotifier < Noticed::Event
class ReceiptNotifier < ApplicationNotifier
deliver_by :test

deliver_by :email do |config|
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/record_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class RecordNotifier < Noticed::Event
class RecordNotifier < ApplicationNotifier
validates :record, presence: true
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/simple_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SimpleNotifier < Noticed::Event
class SimpleNotifier < ApplicationNotifier
deliver_by :test
required_params :message

Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/test_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class TestNotifier < Noticed::Event
class TestNotifier < ApplicationNotifier
deliver_by :test
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/wait_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class WaitNotifier < Noticed::Event
class WaitNotifier < ApplicationNotifier
deliver_by :test, wait: 5.minutes
end
2 changes: 1 addition & 1 deletion test/dummy/app/notifiers/wait_until_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class WaitUntilNotifier < Noticed::Event
class WaitUntilNotifier < ApplicationNotifier
deliver_by :test, wait_until: -> { 1.hour.from_now }
end

0 comments on commit 54a724c

Please sign in to comment.