-
-
Save tcrayford/3018823 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 RubbishController | |
protected | |
def redirect_to(path) | |
puts "redirecting_to #{path}" | |
end | |
def render(renderable) | |
puts "rendering #{renderable}" | |
end | |
def current_user | |
Object.new | |
end | |
def organizations_path(org) | |
"/organizations/#{org.to_param}" | |
end | |
end | |
class ValidationError < RuntimeError | |
end | |
class IgnorePrivate | |
def initialize(thing) | |
@thing = thing | |
end | |
def method_missing(message, *args, &block) | |
@thing.send(message, *args, &block) | |
end | |
end | |
class Organization | |
def to_param | |
"42" | |
end | |
def save! | |
if rand > 0.5 | |
raise ValidationError | |
end | |
end | |
end | |
class OrganizationCreator | |
def initialize(ui) | |
@ui = ui | |
end | |
def create_for(user, org_name) | |
# real creation logic here | |
begin | |
organization = Organization.new | |
organization.save! | |
@ui.organization_creation_succeeded(organization) | |
rescue ValidationError | |
@ui.organization_creation_failed(organization) | |
end | |
end | |
end | |
class OrganizationCreationFeedback | |
def initialize(controller) | |
@controller = controller | |
end | |
def organization_creation_succeeded(org) | |
@controller.redirect_to(@controller.organizations_path(org)) | |
end | |
def organization_creation_failed(org) | |
@controller.render(:error) | |
end | |
end | |
class OrganizationsController < RubbishController | |
def create | |
params = { organization: 'Hello' } | |
feedback = OrganizationCreationFeedback.new(IgnorePrivate.new(self)) | |
creator = OrganizationCreator.new(feedback) | |
creator.create_for(current_user, params[:organization]) | |
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