Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app/use_cases/post_comment.rb
- # Called from the "create" action in a controller
- class PostComment
- def initialize(user, entry, attributes)
- @user = user
- @entry = entry
- @attributes = attributes
- end
- def post
- @comment = @user.comments.new
- @comment.assign_attributes(@attributes)
- @comment.entry = @entry
- @comment.save!
- LanguageDetector.new(@comment).set_language
- SpamChecker.new(@comment).check_spam
- CommentMailer.new(@comment).send_mail
- post_to_twitter if @comment.share_on_twitter?
- post_to_facebook if @comment.share_on_facebook?
- @comment
- end
- private
- def post_to_twitter
- PostToTwitter.new(@user, @comment).post
- end
- def post_to_facebook
- PostToFacebook.new(@user, @comment).action(:comment)
- end
- end
Add Comment
Please, Sign In to add comment