Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Last active December 19, 2015 08:39
Show Gist options
  • Select an option

  • Save nicholasjhenry/5927144 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasjhenry/5927144 to your computer and use it in GitHub Desktop.
Thoughts from Internals and Peers discussion
# Create a nice DSL around the service factories. The DSL becomes a list of commands the Applicaton supports.
module MyApp
module_function
def ship_package(package_id)
service = ShipIssueFactory.build(package_id)
service.call
end
end
class PackageShipmentsController
def create
MyApp.ship_package(params[:package_id]
end
end
# alternatively
class PackageShipmentsController
include MyApp
def create
ship_package(params[:package_id]
end
end
@nicholasjhenry
Copy link
Copy Markdown
Author

I have been undecided whether to pass in package_id or a package object, but migrating it to a background job is trivial when using a package_id:

module MyApp
  class ShipPackageJob < Struct.new(:package_id)
    def perform
      service.call
    end

    private

    def service
      ShipPackageFactory.build(package_id)
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment