Skip to content

Instantly share code, notes, and snippets.

@novikserg
Last active August 29, 2015 14:20
Show Gist options
  • Save novikserg/14be51db4023de55af81 to your computer and use it in GitHub Desktop.
Save novikserg/14be51db4023de55af81 to your computer and use it in GitHub Desktop.
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