Skip to content

Instantly share code, notes, and snippets.

@edlvj
Created September 18, 2020 08:00
Show Gist options
  • Save edlvj/781edeafc0b6ec3a3adb7c7248570bda to your computer and use it in GitHub Desktop.
Save edlvj/781edeafc0b6ec3a3adb7c7248570bda to your computer and use it in GitHub Desktop.
class RecordActivityDecorator < SimpleDelegator
attr_accessor :activity_params
def initialize(object, activity_params)
@activity_params = activity_params
super(object)
end
def save
save_activity if super
end
def save!
save_activity if super
end
def destroy
save_activity if super
end
private
def action
return 'deleted' if __getobj__.destroyed?
__getobj__.id_previously_changed? ? 'created' : 'updated'
end
def save_activity
::Activities::Save.call(
__getobj__,
activity_params[:creator],
action,
activity_params[:params]
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment