-
-
Save JonRowe/3018832 to your computer and use it in GitHub Desktop.
sketch for Matt Wynne
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 Organization | |
def to_param | |
"42" | |
end | |
def saved? | |
rand > 0.5 | |
end | |
end | |
class OrganizationResponder | |
def success(org) | |
puts "redirecting_to #{org_path org}" | |
end | |
def failure(org) | |
puts "rendering error" | |
end | |
def org_path(org) | |
"/organizations/#{org.to_param}" | |
end | |
end | |
class OrganizationCreator | |
def create_for(user, org_name, responder) | |
# real creation logic here | |
organization = Organization.new | |
if organization.saved? | |
responder.success(organization) | |
else | |
responder.failure(organization) | |
end | |
end | |
end | |
class OrganizationsController | |
def create | |
params = { organization: 'Hello' } | |
creator = OrganizationCreator.new | |
creator.create_for(current_user, params[:organization], OrganizationResponder.new) | |
end | |
private | |
def current_user | |
Object.new | |
end | |
end | |
controller = OrganizationsController.new | |
controller.create |
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 Organization | |
def to_param | |
"42" | |
end | |
def saved? | |
rand > 0.5 | |
end | |
end | |
class Renderer < Struct.new(:renderable) | |
def respond | |
puts "rendering #{renderable}" | |
end | |
end | |
class Redirector < Struct.new(:path) | |
def respond | |
puts "redirecting_to #{path}" | |
end | |
end | |
class OrganizationResponder | |
def success(org) | |
Redirector.new( "/organizations/#{org.to_param}" ).respond | |
end | |
def failure(org) | |
Renderer.new(:error).respond | |
end | |
end | |
class OrganizationCreator | |
def create_for(user, org_name, responder) | |
# real creation logic here | |
organization = Organization.new | |
if organization.saved? | |
responder.success(organization) | |
else | |
responder.failure(organization) | |
end | |
end | |
end | |
class OrganizationsController | |
def create | |
params = { organization: 'Hello' } | |
creator = OrganizationCreator.new | |
creator.create_for(current_user, params[:organization], OrganizationResponder.new) | |
end | |
private | |
def current_user | |
Object.new | |
end | |
end | |
controller = OrganizationsController.new | |
controller.create |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment