-
Notifications
You must be signed in to change notification settings - Fork 68
A Simple Example
Attila Domokos edited this page Jun 24, 2013
·
1 revision
# organizer class registered to execute 2 actions
class AddsComment
include LightService::Organizer
def self.to_post(args = {})
with(args).reduce [
SavesCommentAction,
PublishesCommentAction
]
end
end
# action to save comment data
class SavesCommentAction
include LightService::Action
executed do |context|
comment = context.fetch(:comment)
post = context.fetch(:post)
post.comments << comment
post.save
end
end
class PublishesCommentAction
include LightService::Action
executed do |context|
comment = context.fetch(:comment)
comment.publish!
end
end