Module: ActiveJob::Notificare

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_job/notificare.rb,
lib/active_job/notificare/engine.rb,
lib/active_job/notificare/concern.rb,
lib/active_job/notificare/version.rb,
lib/active_job/notificare/step_dsl.rb,
lib/active_job/notificare/recipient.rb,
lib/active_job/notificare/projection.rb,
lib/active_job/notificare/progress_handle.rb,
app/models/active_job/notificare/execution.rb,
app/models/active_job/notificare/notification.rb,
app/helpers/active_job/notificare/view_helpers.rb,
app/models/active_job/notificare/application_record.rb,
app/controllers/active_job/notificare/executions_controller.rb,
app/controllers/active_job/notificare/application_controller.rb,
app/controllers/active_job/notificare/notifications_controller.rb,
lib/generators/active_job/notificare/install/install_generator.rb,
lib/generators/active_job/notificare/scaffold/scaffold_generator.rb

Defined Under Namespace

Modules: Generators, Projection, Recipient, StepDSL, ViewHelpers Classes: ApplicationController, ApplicationRecord, Engine, Execution, ExecutionsController, Notification, NotificationsController, ProgressHandle

Constant Summary collapse

VERSION =
"0.1.0.alpha.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#recipientObject

The polymorphic recipient for notifications. Job authors set this inside perform (e.g. ‘self.recipient = recipient`).



52
53
54
# File 'lib/active_job/notificare/concern.rb', line 52

def recipient
  @recipient
end

Instance Method Details

#notify(title:, description: nil, metadata: {}, actions: []) ⇒ Object

Write a custom Notification row directly. Safe to call at any point during or after perform — does not rely on lifecycle hooks (ERD §9 case 5).

Also flips self.class.uses_notify? to true so subsequent enqueues are subject to recipient enforcement.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/active_job/notificare/concern.rb', line 63

def notify(title:, description: nil, metadata: {}, actions: [])
  self.class.uses_notify!
  return unless recipient

  Notification.create!(
    recipient: recipient,
    job_id: job_id,
    event_type: "custom",
    title: title,
    description: description,
    metadata: .presence,
    actions: actions.presence
  )
end

#progressObject



54
55
56
# File 'lib/active_job/notificare/concern.rb', line 54

def progress
  @progress ||= ProgressHandle.new(job_id)
end