Skip to content

Instantly share code, notes, and snippets.

@kddnewton
Last active September 26, 2022 15:04
Show Gist options
  • Save kddnewton/33da89731cb56ec837110b32f22304df to your computer and use it in GitHub Desktop.
Save kddnewton/33da89731cb56ec837110b32f22304df to your computer and use it in GitHub Desktop.
inlined response
# This class is responsible for publishing a post. This is basically a curried
# global function that is addressable through the PublishPost class. It can be
# easily tested, since its only dependency is the post that it accepts.
class PublishPost
attr_reader :post
def initialize(post)
@post = post
end
def call
# ...
end
end
class Post < ActiveRecord::Base
def release_later
Release::SequenceJob.perform_later(self)
end
# This method is responsible for releasing a post. This involves notifying any
# necessary departments or people. At the end, it publishes the post. It does
# this by invoking the PublishPost class.
def release
prep_marketing_department pizzazz_required: "✨✨✨✨"
some_other_step
PublishPost.new(self).call
end
def publish_later
PublishJob.perform_later(self)
end
def publish
puts "lol"
end
end
class Post::Release::SequenceJob < ApplicationJob
def perform(post)
post.release
end
end
class Post::PublishJob < ApplicationJob
def perform(post)
PublishPost.new(post).call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment