Guest User

Untitled

a guest
Oct 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # app/use_cases/post_comment.rb
  2. # Called from the "create" action in a controller
  3.  
  4. class PostComment
  5. def initialize(user, entry, attributes)
  6. @user = user
  7. @entry = entry
  8. @attributes = attributes
  9. end
  10.  
  11. def post
  12. @comment = @user.comments.new
  13. @comment.assign_attributes(@attributes)
  14. @comment.entry = @entry
  15. @comment.save!
  16.  
  17. LanguageDetector.new(@comment).set_language
  18. SpamChecker.new(@comment).check_spam
  19. CommentMailer.new(@comment).send_mail
  20.  
  21. post_to_twitter if @comment.share_on_twitter?
  22. post_to_facebook if @comment.share_on_facebook?
  23.  
  24. @comment
  25. end
  26.  
  27. private
  28.  
  29. def post_to_twitter
  30. PostToTwitter.new(@user, @comment).post
  31. end
  32.  
  33. def post_to_facebook
  34. PostToFacebook.new(@user, @comment).action(:comment)
  35. end
  36. end
Add Comment
Please, Sign In to add comment