Skip to content

Commit

Permalink
[#105] Complete documentation of notification_target & notification_o…
Browse files Browse the repository at this point in the history
…bject (#106)
  • Loading branch information
jonhue authored and probot-auto-merge[bot] committed Jun 6, 2019
1 parent 5875d1b commit cb94e40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
4 changes: 0 additions & 4 deletions notification-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ You can create a notification from a `target`:
User.first.notify(object: Recipe.first)
```

...

### `notification_object`

When using records of an ActiveRecord class as notification objects, add this to your class:
Expand All @@ -142,8 +140,6 @@ Now associated notifications are easy to access:
notifications = Recipe.first.belonging_notifications
```

...

### Groups

Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
Expand Down
23 changes: 10 additions & 13 deletions notification-handler/lib/notification_handler/object.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# frozen_string_literal: true

require 'active_support'

module NotificationHandler
module Object
def self.included(base)
base.extend(ClassMethods)
end
extend ActiveSupport::Concern

module ClassMethods
def notification_object
included do
def self.notification_object
has_many :belonging_notifications,
as: :object, class_name: 'Notification', dependent: :destroy
include NotificationHandler::Object::InstanceMethods

return unless defined?(NotificationSettings)

include NotificationSettings::Subscribable
# rubocop:disable Style/GuardClause
if defined?(NotificationSettings)
include NotificationSettings::Subscribable
end
# rubocop:enable Style/GuardClause
end
end

module InstanceMethods
# ...
end
end
end
18 changes: 10 additions & 8 deletions notification-handler/lib/notification_handler/target.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

require 'active_support'

module NotificationHandler
module Target
def self.included(base)
base.extend(ClassMethods)
end
extend ActiveSupport::Concern

module ClassMethods
def notification_target
included do
def self.notification_target
has_many :notifications, as: :target, dependent: :destroy
include NotificationHandler::Target::InstanceMethods

include NotificationSettings::Target if defined?(NotificationSettings)
return unless defined?(NotificationSettings)

include NotificationSettings::Subscriber
# rubocop:disable Style/GuardClause
if defined?(NotificationSettings)
include NotificationSettings::Subscriber
end
# rubocop:enable Style/GuardClause
end
end

Expand Down

0 comments on commit cb94e40

Please sign in to comment.