Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created November 30, 2012 12:23
Show Gist options
  • Select an option

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

Select an option

Save nicholasjhenry/4175484 to your computer and use it in GitHub Desktop.
Hexagonal Rails with Responder Objects
class GetItemService < Struct.new( :id, :responder )
def get
item = Item.find( id )
item ? responder.success( item ) : responder.failure( item )
end
end
class GetItemResponder < SimpleDelegator
def success( item )
@item = item
render( "show" )
end
def failure
# handle failure -- render a 404, or whatever
end
end
class ItemsController < ApplicationController
def show
GetItemService.new( params[:id], GetItemResponder.new( self ) ).get
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment