Class: Cats::Core::NotificationService
- Inherits:
-
Object
- Object
- Cats::Core::NotificationService
- Defined in:
- app/services/cats/core/notification_service.rb
Constant Summary collapse
- NOTIFICATION_RULES =
{ dispatch_plan: { application: "CATS-WH", notification: "DispatchPlanNotification", params: [:way_bill], recipients: [:warehouse_manager] }, receipt_plan: { application: "CATS-WH", notification: "ReceiptPlanNotification", params: [:receipt_plan], recipients: [:store_keeper] } }.freeze
Instance Method Summary collapse
- #create_notifier(rule) ⇒ Object
-
#initialize(rules, code, params) ⇒ NotificationService
constructor
A new instance of NotificationService.
- #notify ⇒ Object
Constructor Details
#initialize(rules, code, params) ⇒ NotificationService
Returns a new instance of NotificationService.
19 20 21 22 23 |
# File 'app/services/cats/core/notification_service.rb', line 19 def initialize(rules, code, params) @rules = rules @code = code @params = params end |
Instance Method Details
#create_notifier(rule) ⇒ Object
25 26 27 28 |
# File 'app/services/cats/core/notification_service.rb', line 25 def create_notifier(rule) clazz = rule[:notification].constantize clazz.with(**@params) end |
#notify ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/cats/core/notification_service.rb', line 30 def notify rule = @rules[@code] notifier = create_notifier(rule) app_code = rule[:application] roles = rule[:recipients] users = Cats::Core::User.joins(:application_module) .where(application_module: {prefix: app_code}).with_all_roles(*roles) notifier.deliver(users) end |