Created
September 18, 2020 08:00
-
-
Save edlvj/781edeafc0b6ec3a3adb7c7248570bda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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