A Simple Example - adomokos/light-service GitHub Wiki

# 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