Last active
August 29, 2015 14:20
-
-
Save novikserg/14be51db4023de55af81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CreatePost | |
def self.call(*args) | |
new(*args).call | |
end | |
include Virtus.model | |
attribute :user | |
attribute :post_params | |
attribute :image | |
attribute :accounts | |
attribute :post, Post, writer: :private | |
def call | |
accounts.map do |account| | |
create(account) | |
schedule | |
result | |
end | |
end | |
private | |
def create(account) | |
self.post = account.posts.new(post_params) | |
post.image = image | |
post.save | |
end | |
def schedule | |
SendPost.delay(run_at: post.post_at).call(post: post) | |
end | |
def result | |
post.becomes(Post) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment