module Timeful::Model::Actor::InstanceMethods

Public Instance Methods

publish_activity(action, target:, meta: {}) click to toggle source

Publishes an activity and creates a feed item for each subscriber.

@param action [Symbol] the action (or activity type) to create @param target [ActiveRecord::Base] the target the action was taken upon @param meta [Hash] any metadata to attach to the activity

@return [Activity] the created activity

@example

actor.publish_activity :post_created, target: post # => #<PostCreatedActivity>
# File lib/timeful/model/actor.rb, line 23
def publish_activity(action, target:, meta: {})
  activity = activity_klass(action).create! target: target, meta: meta, actor: self
  DeliverActivityToSubscribersJob.perform_later activity
end

Private Instance Methods

activity_klass(action) click to toggle source
# File lib/timeful/model/actor.rb, line 30
def activity_klass(action)
  "#{action.to_s.camelize}Activity".constantize
end