Skip to content

Instantly share code, notes, and snippets.

@mattsnyder
Created June 26, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsnyder/5868053 to your computer and use it in GitHub Desktop.
Save mattsnyder/5868053 to your computer and use it in GitHub Desktop.
Example of using sentry as guard clause/routing for Rails controllers
class PersonsController
extend ::Sentry
def show
# do stuff
end
sentry_for :show, :expect => [:person], :if_not => :handle_person_not_found
def subscribe
# do stuff
end
sentry_for :subscribe, :expect => [:id], :if_not => :handle_missing_arguments
sentry_for :subscribe, :expect => [:person], :if_not => :handle_person_not_found
protected
def person
PersonRepository.find(id)
end
def id
params[:id]
end
def handle_missing_arguments
render(:text => 'Missing arguments', :status => :internal_server_error, :content_type => Mime::TEXT)
end
def handle_person_not_found
render(:text => 'Not Found', :status => :not_found, :content_type => Mime::TEXT)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment